我一直试图在我的工作站上使用HTTP.sys / HttpListener进行一些测试,似乎存在一些限制,可以防止超过1000个并发连接。还有人知道这方面的更多信息吗?( 1k似乎有点干净,这是个巧合)。
我试图找到任何线程/ config /注册表设置,但结果都是空的。
提前谢谢。
GJ
看来我有点草率了。
我似乎忽略了使用http.sys / HttpListener BeginGetContext并不适合并发连接,因为新的BeginGetContext只有在先前请求的响应流关闭之后才会启动。
所以有1000个请求的积压,在这个例子中,积压正在被填满。
无论如何,如果有人有任何评论(或可能的更正),请随时扩展。
谢谢
GJ
发布于 2010-11-16 10:36:38
我所做的方法是让一个线程使用阻塞的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);
}
}发布于 2010-11-12 03:24:02
下面是一种使用HttpListener支持多个并发请求的简单方法。
for (int i = 0; i < 50; i++) {
_listener.BeginGetContext(GetContextCallback, null);
}这将使您现在能够接收50个并发请求。必须承认,我从来没有尝试过创造1000!
https://stackoverflow.com/questions/4145297
复制相似问题