有没有成熟的、Mono兼容的FastCGI库?

发布于 2024-12-12 08:18:00 字数 228 浏览 0 评论 0原文

我想建立一个在 Mono 上运行的持久应用程序服务器,它需要能够接受 Web 请求并返回一些合适的响应。这是一个简单的任务,几乎就是 FastCGI 的用途,但我似乎找不到不与 ASP.NET 粘合在一起的 FastCGI 解决方案。

需要特别说明的是:我对 ASP.NET 不感兴趣,也不想使用它或尝试选择 ASP.NET 堆栈的任何部分。我真正需要的是一种通过 FastCGI 与网络服务器交互的方法,其余的我可以弄清楚。

I would like to set up a persistent application server running on Mono that needs to be able to accept web requests and return some suitable response. It's a simple task, and pretty much what FastCGI is for, but I can't seem to find a FastCGI solution that is not glued together with ASP.NET.

To be extra clear: I am not interested in ASP.NET and do not want to use it or attempt to co-opt any part of the ASP.NET stack. All I really need is a way to interface with a webserver through FastCGI and I can figure out the rest.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清秋悲枫 2024-12-19 08:18:00

虽然 Mono FastCGI 实现始终与 ASP.NET 服务器打包在一起,但我编写代码的方式使其可以与任何类型的服务器实现一起使用。这是一个应该有效的基本示例。您的请求特定代码位于 Process 方法中,您可以通过 ResponderRequest.GetParameter 访问 FastCGI 环境变量。

using Mono.FastCgi;

public class MyResponder : IResponder {

    RequestResponder req;

    public MyResponder(RequestResponder req) {
        req = request;
    }

    public int Process() {
        req.SendOutput("Content-Type: text/plain\r\n\r\n");
        req.SendOutput("Server name: ");
        req.SendOutput(req.GetParameter("SERVER_NAME");
        return 0;
    }

    public ResponderRequest Request {
        get {return req;}
    }


    public static void Main() {
        Socket socket = SocketFactory.CreatePipeSocket(IntPtr.Zero);
        //            = SocketFactory.CreateTcpSocket(address, port);
        //            = SocketFactory.CreateUnixSocket(path);

        Server server = new Server(socket);

        server.SetResponder(typeof (MyResponder));
        server.Start(false);
    }
}

要构建此示例,您可以从 https 下载所有 CS 文件: //github.com/mono/xsp/tree/master/src/Mono.WebServer.FastCgi 并排除任何不使用 Mono.FastCgi 命名空间的文件。

While the Mono FastCGI implementation is always packaged with a ASP.NET server, I wrote the code in such a way that it can be used with any sort of server implementation. Here is a basic example that should work. Your request specific code goes in the Process method and you can access FastCGI environment variables through ResponderRequest.GetParameter.

using Mono.FastCgi;

public class MyResponder : IResponder {

    RequestResponder req;

    public MyResponder(RequestResponder req) {
        req = request;
    }

    public int Process() {
        req.SendOutput("Content-Type: text/plain\r\n\r\n");
        req.SendOutput("Server name: ");
        req.SendOutput(req.GetParameter("SERVER_NAME");
        return 0;
    }

    public ResponderRequest Request {
        get {return req;}
    }


    public static void Main() {
        Socket socket = SocketFactory.CreatePipeSocket(IntPtr.Zero);
        //            = SocketFactory.CreateTcpSocket(address, port);
        //            = SocketFactory.CreateUnixSocket(path);

        Server server = new Server(socket);

        server.SetResponder(typeof (MyResponder));
        server.Start(false);
    }
}

To build this example, you can download all the CS files from https://github.com/mono/xsp/tree/master/src/Mono.WebServer.FastCgi and just exclude any files that don't use the Mono.FastCgi namespace.

极度宠爱 2024-12-19 08:18:00

也许您可以将 FASTCGI C 库连接到 Mono。

另一种可能性是使用 SCGI 协议。该协议(某种程度上比 FastCGI 效率低)与 FastCGI 共享让持久应用程序为 Web 服务器工作的能力。但 SCGI 非常简单,编写您自己的 SCGI 协议实现非常简单(假设您具有 HTTP 的应用知识)。

Perhaps you might interface the FASTCGI C library to Mono.

Another possibility could be to use the SCGI protocol. That protocol (somehow less efficient than FastCGI) share with FastCGI the ability to have a persistent application working for a web server. But SCGI is so simple that writing your own SCGI protocol implementation is very simple (assuming you have a working knowledge of HTTP).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文