Пример #1
0
        /// <summary>
        /// Starts the server.
        /// </summary>
        public void Start()
        {
            if (_state == HttpServerState.Stopped)
            {
                State = HttpServerState.Starting;
                Console.WriteLine("Server Starting at {0} ...", EndPoint.Address);

                TimeoutManager = new HttpTimeoutManager(this);
                TcpListener listener = new TcpListener(EndPoint);
                try
                {
                    listener.Start();
                    EndPoint      = (IPEndPoint)listener.LocalEndpoint;
                    _listener     = listener;
                    ServerUtility = new HttpServerUtility();
                    Console.WriteLine("Server Running at {0} ...", EndPoint.Address);
                }
                catch (Exception exception)
                {
                    State = HttpServerState.Stopped;
                    Console.WriteLine("Failed starting the server: {0}", exception.Message);
                    throw new PHttpException("Failed starting the server.", exception);
                }
                State = HttpServerState.Started;
                BeginAcceptTcpClient();
            }
        }
Пример #2
0
        public void Start()
        {
            VerifyState(HttpServerState.Stopped);

            State = HttpServerState.Starting;



            TimeoutManager = new HttpTimeoutManager(this);

            // Start the listener.

            var listener = new TcpListener(EndPoint);

            try
            {
                listener.Start();

                EndPoint = (IPEndPoint)listener.LocalEndpoint;

                _listener = listener;

                ServerUtility = new HttpServerUtility();
            }
            catch (Exception ex)
            {
                State = HttpServerState.Stopped;

                throw new PHttpException("Failed to start HTTP server", ex);
            }

            State = HttpServerState.Started;

            BeginAcceptTcpClient();
        }
Пример #3
0
        public void Start()
        {
            VerifyState(HttpServerState.Stopped);
            State = HttpServerState.Starting;
            Console.WriteLine("-- Server Starting at EndPoint {0}:{1}", EndPoint.Address, EndPoint.Port);
            TimeoutManager = new HttpTimeoutManager(this);
            var listener = new TcpListener(EndPoint);

            try
            {
                listener.Start();
                EndPoint      = listener.LocalEndpoint as IPEndPoint;
                _listener     = listener;
                ServerUtility = new HttpServerUtility();
                Console.WriteLine("-- Server Running at EndPoint {0}:{1}", EndPoint.Address, EndPoint.Port);
            }
            catch (Exception ex)
            {
                State = HttpServerState.Stopped;
                Console.WriteLine("** Failed to start HTTP server. | Exception: " + ex.Message);
                throw new PHttpException("Failed to start HTTP server.");
            }
            State = HttpServerState.Started;
            BeginAcceptTcpClient();
        }
Пример #4
0
        public void Dispose()
        {
            if (!_disposed)
            {
                if (_state == HttpServerState.Started)
                {
                    Stop();
                }

                if (_clientsChangedEvent != null)
                {
                    ((IDisposable)_clientsChangedEvent).Dispose();
                    _clientsChangedEvent = null;
                }

                if (TimeoutManager != null)
                {
                    TimeoutManager.Dispose();
                    TimeoutManager = null;
                }

                _disposed = true;
            }
        }