Example #1
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="HttpServer"/> class.
        /// </summary>
        /// <param name="scheme">The transport server scheme used.</param>
        /// <param name="port">The port the HTTP server is using to listen for traffic.</param>
        /// <param name="handler">The default <see cref="IHttpHandler"/> executed when receiving traffic.</param>
        /// <exception cref="ArgumentNullException">handler</exception>
        /// <exception cref="ArgumentOutOfRangeException">port</exception>
        /// <exception cref="ArgumentNullException"><paramref name="handler" /> is <c>null</c>.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="port"/> exceeds the allowed TCP port range.</exception>
        public HttpServer(ServerScheme scheme, int port, IHttpHandler handler)
        {
            _handler = handler ?? throw new ArgumentNullException(nameof(handler));

            if (port < IPEndPoint.MinPort || port > IPEndPoint.MaxPort)
            {
                throw new ArgumentOutOfRangeException(nameof(port));
            }

            _listener = new HttpListener();
            _port     = port;
            _scheme   = scheme;
        }
Example #2
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="T:Stumps.Http.HttpServer"/> class.
        /// </summary>
        /// <param name="port">The port the HTTP server is using to listen for traffic.</param>
        /// <param name="handler">The default <see cref="T:Stumps.Http.IHttpHandler"/> executed when receiving traffic.</param>
        /// <exception cref="System.ArgumentNullException">
        /// <paramref name="handler"/> is <c>null</c>.
        /// </exception>
        /// <exception cref="System.ArgumentOutOfRangeException"><paramref name="port"/> exceeds the allowed TCP port range.</exception>
        public HttpServer(ServerScheme scheme, int port, IHttpHandler handler)
        {

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

            if (port < IPEndPoint.MinPort || port > IPEndPoint.MaxPort)
            {
                throw new ArgumentOutOfRangeException("port");
            }

            _listener = new HttpListener();
            _port = port;
            _scheme = scheme;
            _handler = handler;

        }