3

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.

2 Answers 2

2

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.

1
  • Brian, thanks for your great work on this! I have a related SO question about hosting a mono app that relies on static variables and I would greatly appreciate it if you had time to chime in on the question: stackoverflow.com/questions/13480328/…
    – Glenn
    Nov 20, 2012 at 20:12
0

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).

1
  • Since there doesn't seem to be any good FastCGI .NET libraries, I'll give SimpleCGI a shot and marking this answer as accepted. Cheers.
    – pjohansson
    Oct 31, 2011 at 13:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.