Exemplo n.º 1
0
        /// <summary>
        /// Starts the HTTP/HTTPS server
        /// </summary>
        public void Start()
        {
            lock (this)
                if (IsDisposed)
                {
                    throw new ObjectDisposedException(nameof(HTTPServer));
                }

            if (FirewallUtils.IsPortOpen(Port))
            {
                FirewallUtils.ClosePort(Port);
            }

            FirewallUtils.OpenPort(Port, "WWS4.0 HTTP/HTTPS Server");

            _listener.Start();

            Task.Factory.StartNew(async() =>
            {
                while (true)
                {
                    lock (this)
                        if (IsDisposed)
                        {
                            break;
                        }

                    if (_listener.IsListening)
                    {
                        await ListenAsync(_listener);
                    }
                }
            }, TaskCreationOptions.LongRunning);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Stops the server and releases all underlying resources
        /// </summary>
        public void Stop()
        {
            lock (this)
                if (!IsDisposed)
                {
                    if (_listener.IsListening)
                    {
                        _listener.Stop();
                    }

                    if (FirewallUtils.IsPortOpen(Port))
                    {
                        FirewallUtils.ClosePort(Port);
                    }

                    _listener.Close();
                    IsDisposed = true;
                }
        }