/// <summary> /// Creates an instance of the Woopsa server without using the Reflector. You /// will have to create the object hierarchy yourself, using WoopsaObjects /// or implementing IWoopsaContainer yourself. /// /// If you are already using a <see cref="WebServer"/> somewhere else, /// this constructor will simply add the woopsa routes to that server. /// This allows you to serve static content and the Woopsa protocol /// on the same network interface and on the same port. /// </summary> /// <param name="root">The root object that will be published via Woopsa.</param> /// <param name="server">The server on which Woopsa routes will be added</param> /// <param name="routePrefix"> /// The prefix to add to all routes for woopsa verbs. For example, specifying /// "myPrefix" will make the server available on http://server/myPrefix /// </param> public WoopsaServer(IWoopsaContainer root, WebServer server, string routePrefix = DefaultServerPrefix) { _root = root; WebServer = server; _routePrefix = routePrefix; AddRoutes(); }
private void Listen() { _currentWebServer = this; while (!_aborted && _started) { try { // The HandleClient method will loop in case of // Keep-Alive connections. // The HandleClient method should NEVER close the stream // as this is done from the upper scope. TcpClient client = _listener.AcceptTcpClient(); if (MultiThreaded) { try { _threadPool.StartUserWorkItem( (o) => { _currentWebServer = this; try { HandleClient(client); } finally { client.Close(); } }); } catch (Exception) { client.Close(); throw; } } else { try { HandleClient(client); } finally { client.Close(); } } } catch (SocketException e) { if (e.SocketErrorCode == SocketError.Interrupted) { _aborted = true; } } catch (Exception) { // TODO : mechanism to manage exceptions } } _listener.Stop(); }
protected virtual void Dispose(bool disposing) { if (disposing) { ShutDown(); RemoveRoutes(); if (_subscriptionService != null) { _subscriptionService.Dispose(); _subscriptionService = null; } if (_isWebServerEmbedded) { WebServer.Dispose(); WebServer = null; } } }