2010-11-10 69 views
6

我一直在尝试在我的工作站上使用HTTP.sys/HttpListener进行一些测试,并且似乎有一些限制阻止了更多那1000个并发连接。有没有人有关于此的更多信息? (因为1k似乎有点清理是巧合)。Windows 7旗舰版x64上的System.Net.HttpListener限制为1k并发连接

我试图找到任何线程/配置/注册表设置,但已经空了。

在此先感谢。
GJ


貌似我偷步有点。

我似乎错过了使用http.sys/HttpListener BeginGetContext不是很好的并发连接,因为新的BeginGetContext只会在先前请求的响应流关闭后触发。

所以有1000个请求的积压,在这种情况下积压正在填满。无论如何 - 如果任何人有任何意见(或可能的更正),随意扩大。

感谢
GJ

回答

5

我已经做到了是为具有对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); 
     } 
    } 
+0

干杯罗布 - 这让我过度了! – CameraSchoolDropout 2010-11-17 12:17:31

0

这里有一个简单的方法来支持与HttpListener多个并发请求。

 for (int i = 0; i < 50; i++) { 
      _listener.BeginGetContext(GetContextCallback, null); 
     } 

这现在将使您能够接收50个并发请求。必须承认,我从来没有尝试过创造1000!

+0

谢谢达雷尔 - 这个工作,但不幸的是不适合我面临的问题。 – CameraSchoolDropout 2010-11-14 11:37:59

相关问题