Manages the WebSocket services provided by the HttpServer and WebSocketServer.
        /// <summary>
        /// Initializes a new instance of the <see cref="HttpServer"/> class that
        /// listens for incoming requests on the specified <paramref name="port"/>
        /// and <paramref name="secure"/>.
        /// </summary>
        /// <param name="port">
        /// An <see cref="int"/> that contains a port number.
        /// </param>
        /// <param name="secure">
        /// A <see cref="bool"/> that indicates providing a secure connection or not.
        /// (<c>true</c> indicates providing a secure connection.)
        /// </param>
        /// <exception cref="ArgumentOutOfRangeException">
        /// <paramref name="port"/> is not between 1 and 65535.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// Pair of <paramref name="port"/> and <paramref name="secure"/> is invalid.
        /// </exception>
        public HttpServer(int port, bool secure)
        {
            if (!port.IsPortNumber())
            {
                throw new ArgumentOutOfRangeException(
                          "port", "Must be between 1 and 65535: " + port);
            }

            if ((port == 80 && secure) || (port == 443 && !secure))
            {
                throw new ArgumentException(
                          String.Format(
                              "Invalid pair of 'port' and 'secure': {0}, {1}", port, secure));
            }

            _port         = port;
            _secure       = secure;
            _listener     = new HttpListener();
            _logger       = new Logger();
            _serviceHosts = new WebSocketServiceHostManager(_logger);
            _state        = ServerState.READY;
            _sync         = new object();

            var os = Environment.OSVersion;

            if (os.Platform != PlatformID.Unix && os.Platform != PlatformID.MacOSX)
            {
                _windows = true;
            }

            var prefix = String.Format("http{0}://*:{1}/", _secure ? "s" : "", _port);

            _listener.Prefixes.Add(prefix);
        }
Пример #2
0
 private void init()
 {
     _listener     = new TcpListener(_address, _port);
     _logger       = new Logger();
     _serviceHosts = new WebSocketServiceHostManager(_logger);
     _state        = ServerState.READY;
     _sync         = new object();
 }
 private void init()
 {
     _authSchemes  = AuthenticationSchemes.Anonymous;
     _listener     = new TcpListener(_address, _port);
     _logger       = new Logger();
     _serviceHosts = new WebSocketServiceHostManager(_logger);
     _state        = ServerState.READY;
     _sync         = new object();
 }
        private void init()
        {
            _listener     = new HttpListener();
            _logger       = new Logger();
            _serviceHosts = new WebSocketServiceHostManager(_logger);
            _state        = ServerState.READY;
            _sync         = new object();

            _windows = false;
            var os = Environment.OSVersion;

            if (os.Platform != PlatformID.Unix && os.Platform != PlatformID.MacOSX)
            {
                _windows = true;
            }

            var prefix = String.Format("http{0}://*:{1}/", _secure ? "s" : "", _port);

            _listener.Prefixes.Add(prefix);
        }