示例#1
0
        private static void Main()
        {
            ConsoleTraceListener.Bind();

            HttpServer server = null;

            for (var port = 8000; port <= 65535; ++port)
            {
                server = new HttpServer(IPAddress.Loopback, port);
                try
                {
                    server.Start();
                }
                catch (SocketException)
                {
                    continue;
                }
                break;
            }

            Console.WriteLine("Hit return to exit");
            Console.ReadLine();

            Console.WriteLine("Stopping...");
            server.Dispose(); // TODO: this should be waiting for requests to end
            Console.WriteLine("Stopped.");
        }
        public static ConsoleTraceListener Bind()
        {
            var listener = Trace.Listeners.OfType <ConsoleTraceListener>().FirstOrDefault();

            if (listener == null)
            {
                Trace.Listeners.Add(listener = new ConsoleTraceListener());
            }

            return(listener);
        }