Esempio n. 1
0
        static void Main(string[] args)
        {
            var router = new CatchAllRouter(async (req, res) =>
            {
                var data = Encoding.UTF8.GetBytes("Hello World");
                res.Headers["Content-Length"] = data.Length.ToString();
                await res.Start(200);
                await res.Write("Hello World");
                await res.Finish();
            });

            using (var server = new Server(router, 1))
            {
                //Start listening for requests
                server.Run(new System.Net.IPEndPoint(System.Net.IPAddress.Any, 8888));

                Console.WriteLine("Server started");
                Console.WriteLine("Listening on port 8888");
                Console.WriteLine("Press CTRL+C to exit");

                // Quit on CTRL-C
                Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e)
                {
                    e.Cancel = true;
                    Running = false;
                    Console.WriteLine("Shutting down...");
                };

                //Run until the user exits
                while (Running) System.Threading.Thread.Sleep(100);
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            using (var server = new Server(URLRouter.Discover()))
            {
                //Start listening for requests
                server.Run(new System.Net.IPEndPoint(System.Net.IPAddress.Any, 8888));

                Console.WriteLine("Server started");
                Console.WriteLine("Listening on port 8888");
                Console.WriteLine("Press CTRL+C to exit");

                // Quit on CTRL-C
                Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e)
                {
                    e.Cancel = true;
                    Running = false;
                    Console.WriteLine("Shutting down...");
                };

                //Run until the user exits
                while (Running) System.Threading.Thread.Sleep(100);
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            // The folder we're going to serve from
            string folder = Environment.CurrentDirectory;

            // If an argument is specified, it's the directory we should serve
            if (args.Length > 0)
                folder = Path.Combine(Environment.CurrentDirectory, args[0]);

            // Ensure the folder exists
            DirectoryInfo dir = new DirectoryInfo(folder);
            if (!dir.Exists)
            {
                Console.WriteLine("Cannot serve from {0} because it doesn't exist!", folder);
                Environment.Exit(1);
            }

            // Fire up the server!
            using (var server = new Server(new CatchAllRouter(new FileServer(folder).Serve)))
            {
                //Start listening for requests
                server.Run(new System.Net.IPEndPoint(System.Net.IPAddress.Any, 8888));

                Console.WriteLine("Server started");
                Console.WriteLine("Listening on port 8888");
                Console.WriteLine("Serving from {0}", folder);
                Console.WriteLine("Press CTRL+C to exit");
                Console.WriteLine("");

                // Quit on CTRL-C
                Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e)
                {
                    e.Cancel = true;
                    Running = false;
                    Console.WriteLine("Shutting down...");
                };

                //Run until the user exits
                while (Running) System.Threading.Thread.Sleep(100);
            }
        }