System.net.httplistener on Windows 7 Ultimate x64に1Kの並行接続に制限されています
-
30-09-2019 - |
質問
私はワークステーションでHTTP.SYS / HTTPLISTENERでいくつかのテストを試みてきましたが、1000の並行接続を防ぐ制限があるようです。誰かがこれについてこれ以上情報を持っていますか? (1kは偶然になるために少しきれいに思えます)。
スレッド /構成 /レジストリの設定を見つけようとしましたが、空っぽになりました。
前もって感謝します。
GJ
銃を少し飛び越えたようです。
http.sys / httplistener begingetcontextを使用することは、以前のリクエストからの応答ストリームが閉じた後にのみ新しいBgingetContextが発射するため、同時接続にはあまり良くないことを逃したようです。
そのため、1000のリクエストのバックログがあり、この場合はバックログがいっぱいになっています。
とにかく - 誰かがコメント(またはおそらく修正)がある場合は、自由に拡大してください。
ありがとう
GJ
解決
私がやった方法は、 HttpListener
ブロッキングを使用します GetContext()
方法ですが、リクエストを受信するとすぐに、それを別のスレッドに渡します。 IAsyncResult
パターンとこれは正常に機能しているようです。
private void Run()
{
while (true)
{
if (this._disposed || this._shouldTerminate) return;
if (this._listener.IsListening)
{
try
{
HttpListenerContext context = this._listener.GetContext();
//Hand it off to be processed asynchronously
this._delegate.BeginInvoke(context, new AsyncCallback(this.EndRequest), null);
}
catch (Exception ex)
{
this.LogErrors(ex);
}
}
}
}
private delegate HttpServerContext HandleRequestDelegate(HttpListenerContext context);
private HttpServerContext HandleRequest(HttpListenerContext context)
{
IHttpListenerHandler handler;
HttpServerContext serverContext = new HttpServerContext(this, context);
try
{
bool skipHandling = this.ApplyPreRequestModules(serverContext);
if (!skipHandling)
{
handler = this._handlers.GetHandler(serverContext);
handler.ProcessRequest(serverContext);
}
}
catch (NoHandlerException noHandlerEx)
{
this.LogErrors(noHandlerEx);
context.Response.StatusCode = (int)HttpStatusCode.MethodNotAllowed;
}
catch (HttpServerException serverEx)
{
this.LogErrors(serverEx);
context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
}
return serverContext;
}
private void EndRequest(IAsyncResult result)
{
try
{
HttpServerContext context = this._delegate.EndInvoke(result);
this.ApplyPreResponseModules(context);
context.Response.Close();
}
catch (Exception ex)
{
this.LogErrors(ex);
}
}
他のヒント
HTTPlistenerとの複数の同時リクエストをサポートするための単純なアプローチを次に示します。
for (int i = 0; i < 50; i++) {
_listener.BeginGetContext(GetContextCallback, null);
}
これにより、50の同時リクエストを受信できるようになりました。認めなければなりません、私は1000を作成しようとしたことがありません!
所属していません StackOverflow