Cam*_*out 6 .net sockets httplistener
我一直在尝试使用我的工作站上的HTTP.sys/HttpListener进行一些测试,似乎有一些限制可以防止超过1000个并发连接.有没有人有这方面的更多信息?(因为1k似乎有点清洁是巧合).
我试图找到任何线程/配置/注册表设置但是空了.
提前致谢.
GJ
看起来我跳了一下枪.
我似乎错过了使用http.sys/HttpListener BeginGetContext对并发连接不是很好,因为新的BeginGetContext只会在先前请求的响应流关闭后触发.
因此积压了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);
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1742 次 |
最近记录: |