コード例 #1
0
        public WebServer(int port, bool localOnly, ReqRespHandler <HttpRequest, HttpResponse> reqHandler)
        {
            this.reqHandler = reqHandler;

            int maxNumberOfConnections  = 1000;
            int excessSaeaObjectsInPool = 200;
            int backlog = 100;
            int maxSimultaneousAcceptOps = 100;

            var setting = new NewConnListenerSettings(maxNumberOfConnections,
                                                      excessSaeaObjectsInPool,
                                                      backlog,
                                                      maxSimultaneousAcceptOps,
                                                      new IPEndPoint(localOnly ? IPAddress.Loopback : IPAddress.Any, port));//check only local host or not

            CreateContextPool(maxNumberOfConnections);
            newConnListener = new NewConnectionListener(setting,
                                                        clientSocket =>
            {
                //when accept new client
                HttpContext context = this.contextPool.Pop();
                context.BindSocket(clientSocket); //*** bind to client socket
                context.StartReceive();           //start receive data
            });
        }
コード例 #2
0
        public void Start()
        {
            if (_isRunning)
            {
                return;
            }
            //------------------------------
            try
            {
                //------------------------------
                int maxNumberOfConnections  = 500;
                int excessSaeaObjectsInPool = 200;
                int backlog = 100;
                int maxSimultaneousAcceptOps = 100;

                var setting = new NewConnListenerSettings(maxNumberOfConnections,
                                                          excessSaeaObjectsInPool,
                                                          backlog,
                                                          maxSimultaneousAcceptOps,
                                                          new IPEndPoint(_localOnly ? IPAddress.Loopback : IPAddress.Any, _port));//check only local host or not

                CreateContextPool(maxNumberOfConnections);
                _newConnListener = new NewConnectionListener(setting,
                                                             clientSocket =>
                {
                    //when accept new client

                    int recvSize         = 1024 * 2;
                    int sendSize         = 1024 * 2;
                    HttpsContext context = new HttpsContext(this, recvSize, sendSize);
                    context.BindReqHandler(_reqHandler);     //client handler
#if DEBUG
                    context.dbugForHttps = true;
#endif


                    context.BindSocket(clientSocket); //*** bind to client socket
                                                      //for ssl -> cert must not be null
                    context.StartReceive(_serverCert);
                    //TODO::
                    //USE https context from Pool????
                    //{
                    //    HttpsContext context = _contextPool.Pop();
                    //    context.BindSocket(clientSocket); //*** bind to client socket
                    //    context.StartReceive(UseSsl ? _serverCert : null);
                    //}
                });
                //------------------------------


                //start web server
                _isRunning = true;
                _newConnListener.StartListening();
            }
            catch (Exception ex)
            {
            }
        }
コード例 #3
0
        public void Start()
        {
            if (_isRunning)
            {
                return;
            }
            //------------------------------
            try
            {
                int maxNumberOfConnections  = 500;
                int excessSaeaObjectsInPool = 200;
                int backlog = 100;
                int maxSimultaneousAcceptOps = 100;

                var setting = new NewConnListenerSettings(maxNumberOfConnections,
                                                          excessSaeaObjectsInPool,
                                                          backlog,
                                                          maxSimultaneousAcceptOps,
                                                          new IPEndPoint(_localOnly ? IPAddress.Loopback : IPAddress.Any, _port));//check only local host or not

                CreateContextPool(maxNumberOfConnections);
                _newConnListener = new NewConnectionListener(setting,
                                                             clientSocket =>
                {
                    //when accept new client
                    HttpContext context = _contextPool.Pop();
                    context.BindSocket(clientSocket); //*** bind to client socket
                    context.StartReceive();           //start receive data
                });
                //start web server
                _isRunning = true;
                _newConnListener.StartListening();
            }
            catch (Exception ex)
            {
            }
        }