1

C# Mono (Linux では Mono バージョン 3.12.1) サーバーでパイプライン化されたリクエストを処理する必要がありますが、パイプラインの 2 番目のリクエストが常に無視されることに気付きました。

パイプラインをテストするための netcat コマンドは次のとおりです。

nc -v localhost 5000 < httppipe.txt 

httppipe.txt の内容は次のとおりです。

GET /heartbeat HTTP/1.1
Host: localhost

GET /heartbeat HTTP/1.1
Host: localhost

Java サーバーで正常にテストしたため、netcat のアプローチが機能すると確信しています。(つまり、私は 2 つの応答を見ました)

私の C# サーバーでは、GetResult と GetResultAsync の両方を試しました。GetResultAsync を使用したコードは、基本的に MSDN の例からそのまま引用されています。次のようになります。

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(); 
        }

編集:LinuxでMono 4.0でも試してみましたが、役に立ちませんでした。

4

0 に答える 0