Stumps.StumpsServer.Start C# (CSharp) Method

Start() public method

Starts this instance of the Stumps server.
public Start ( ) : void
return void
        public void Start()
        {
            lock (_syncRoot)
            {

                if (_started)
                {
                    return;
                }

                _started = true;

                // Setup the pipeline HTTP handler
                var pipeline = new HttpPipelineHandler();

                // Setup the Stump HTTP handler
                _stumpsHandler = new StumpsHandler(_stumpsManager);
                _stumpsHandler.Enabled = this.StumpsEnabled;

                pipeline.Add(_stumpsHandler);

                // Setup the Proxy HTTP handler
                if (_remoteHttpServer != null)
                {
                    var proxyHandler = new ProxyHandler(_remoteHttpServer);
                    pipeline.Add(proxyHandler);
                }
                else
                {
                    // Setup the Service Unavailable HTTP handler
                    var stumpNotFoundHandler = new FallbackResponseHandler(_defaultResponse);
                    pipeline.Add(stumpNotFoundHandler);
                }

                var scheme = _useHttpsForIncommingConnections ? ServerScheme.Https : ServerScheme.Http;
                _server = new HttpServer(scheme, _port, pipeline);

                _server.RequestFinished += ServerRequestFinished;
                _server.RequestProcessed += ServerRequestProcessed;
                _server.RequestReceived += ServerRequestStarted;

                _server.StartListening();

            }
        }

Usage Example

Example #1
0
        /// <summary>
        ///     Defines the entry point of the application.
        /// </summary>
        /// <param name="args">The command-line arguments.</param>
        public static void Main(string[] args)
        {
            ConsoleHelper.ApplicationBanner("Hello World API");

            // Create a new Stumps Server
            var server = new StumpsServer();

            // An open port will be chosen automatically unless specified
            // server.ListensOnPort = 9100;

            // Create a new Stump for the server
            var stump = new Stump("HelloWorldStump");

            // Add two rules that stumps out HTTP GET requests for the url /HeloWorld.htm
            stump.AddRule(new HttpMethodRule("GET"));
            stump.AddRule(new UrlRule("/HelloWorld.htm"));

            // Create a response for the rule
            var response = new BasicHttpResponse();
            response.Headers["Content-Type"] = "text/html;charset=UTF-8";
            response.AppendToBody(
                "<html><header><title>Stumps Hello World</title></header><body><p>Hello From Stumps</p></body></html>");

            // Add the response to the stump
            stump.Response = response;

            // Add the stump to the server
            server.AddStump(stump);

            // Show the requests that are incomming
            server.RequestProcessed += (o, e) => ConsoleHelper.ShowHttpResponse(server, e);

            // Start the server and wait!
            server.Start();

            // Show the URL to the user
            Console.WriteLine("Browse to http://localhost:{0}/HelloWorld.htm", server.ListeningPort);
            Console.WriteLine();

            // Wait to exit
            ConsoleHelper.WaitForExit();

            server.Shutdown();
            server.Dispose();
        }
All Usage Examples Of Stumps.StumpsServer::Start