예제 #1
0
        public HttpServer(IHttpHandler app, HttpServerSettings settings)
        {
            if (app == null) throw new ArgumentNullException("app");
            if (settings == null) throw new ArgumentNullException("settings");

            // init asp.net host
            if (settings.AspNetHost)
            {
                var appHost = new AppHost(settings);
                appHost.Init();
            }

            IHttpListener listener;

            switch (settings.Mode)
            {
                case HttpServerMode.TcpListener:
                    listener = new TcpListenerImpl(app, settings);
                    break;
                case HttpServerMode.HttpListener:
                    listener = new HttpListenerImpl(app, settings);
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }

            _listener = listener;
            _listener.Start();

            _listenerThread = new Thread(Listen);
            _listenerThread.Start();
        }
예제 #2
0
        public HttpServer(IHttpHandler app, HttpServerSettings settings)
        {
            if (app == null)
            {
                throw new ArgumentNullException("app");
            }
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            // init asp.net host
            if (settings.AspNetHost)
            {
                var appHost = new AppHost(settings);
                appHost.Init();
            }

            IHttpListener listener;

            switch (settings.Mode)
            {
            case HttpServerMode.TcpListener:
                listener = new TcpListenerImpl(app, settings);
                break;

            case HttpServerMode.HttpListener:
                listener = new HttpListenerImpl(app, settings);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            _listener = listener;
            _listener.Start();

            _listenerThread = new Thread(Listen);
            _listenerThread.Start();
        }