/// <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); }
/// <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; } }