Пример #1
0
        private EmbeddedWebServer(HttpRequestHandler handler)
        {
            if (!HttpListener.IsSupported)
            {
                Console.WriteLine("Windows XP SP2 or Server 2003 is required to use the HttpListener class.");
                throw new NotSupportedException("SimpleListenerExample");
            }

            if (handler == null)
            {
                throw new ArgumentNullException("handler");
            }

            this._httpHandler = handler;

            // Setup the web sockets
            _socketServer = new WebSocketServer();
            var serverConfig = new SuperSocket.SocketBase.Config.ServerConfig
            {
                Name = "SuperWebSockets",
                Ip   = "Any",
                Port = handler.WebSocketPort,
                Mode = SocketMode.Tcp
            };
            var rootConfig = new SuperSocket.SocketBase.Config.RootConfig();
            var factory    = new SuperSocket.SocketEngine.SocketServerFactory();

            _socketServer.NewSessionConnected += _socketServer_NewSessionConnected;
            _socketServer.SessionClosed       += _socketServer_SessionClosed;
            _socketServer.NewMessageReceived  += _socketServer_NewMessageReceived;
            _socketServer.NewDataReceived     += _socketServer_NewDataReceived;
            _socketServer.Setup(rootConfig, serverConfig, factory);
            _socketServer.Start();

            // Setup the web server
            _httpListener = new HttpListener();
            _httpListener.Prefixes.Add(handler.WebPrefix);
            _httpListener.Start();
            StartListening();

            string chromeArgs = " --app=" + handler.WebPrefix;

            System.Diagnostics.Process.Start(handler.PathOfChromeExecutable, chromeArgs);
        }
Пример #2
0
 // This example requires the System and System.Net namespaces.
 public static EmbeddedWebServer StartServer(HttpRequestHandler handler)
 {
     return(new EmbeddedWebServer(handler));
 }