1

I need to handle pipelined requests in my C# Mono (Mono version 3.12.1 on Linux) server, but I noticed that the second request in the pipeline is always ignored.

Here's my netcat command to test pipelining:

nc -v localhost 5000 < httppipe.txt 

Here's the contents of httppipe.txt:

GET /heartbeat HTTP/1.1
Host: localhost

GET /heartbeat HTTP/1.1
Host: localhost

I'm pretty confident my netcat approach works because I tested it on a Java server successfully. (Meaning I saw 2 responses)

In my C# server, I've tried both GetResult and GetResultAsync. The code with GetResultAsync is basically pulled right from the MSDN example. It looks like this:

this.Listener = new HttpListener();
this.Listener.Prefixes.Add(uriPrefix);
this.Listener.BeginGetContext(new AsyncCallback(ListenerCallback),this.Listener);

public static void ListenerCallback(IAsyncResult result)
        {
            HttpListener listener = (HttpListener) result.AsyncState;
            // Call EndGetContext to complete the asynchronous operation.
            HttpListenerContext context = listener.EndGetContext(result);
            listener.BeginGetContext(new AsyncCallback(ListenerCallback), listener);
            HttpListenerRequest request = context.Request;
            // Obtain a response object.
            HttpListenerResponse response = context.Response;
            // Construct a response. 
            string responseString = "<HTML><BODY> Hello world!</BODY></HTML>";
            byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
            // Get a response stream and write the response to it.
            response.ContentLength64 = buffer.Length;
            System.IO.Stream output = response.OutputStream;
            output.Write(buffer,0,buffer.Length);
            // You must close the output stream.
            output.Close(); 
        }

EDIT: Also tried on Mono 4.0 on Linux to no avail.

Newtang
  • 6,414
  • 10
  • 49
  • 70

0 Answers0