/** * This {@link HttpServer} will accept connections on the {@code endpoint} and will handle each with the * <var>httpClientConnectionHandler</var>. * * @param endpoint The {@link InetAddress} and local port the server will bind to; {@link * InetSocketAddress#InetSocketAddress(int)} will accept connections on any/all local addresses; * port number zero will pick an ephemeral port */ public HttpServer( InetSocketAddress endpoint, final HttpClientConnectionHandler httpClientConnectionHandler ) throws IOException { this.tcpServer = new TcpServer(endpoint, 0, httpClientConnectionHandler); }
/** * @return The endpoint address of this HTTP server * @see TcpServer#getEndpointAddress() */ public InetSocketAddress getEndpointAddress() { return this.tcpServer.getEndpointAddress(); } }
@Override public void run() throws IOException { this.server.run(); }
@Override public void stop() { this.tcpServer.stop(); } }
/** * Creates a (non-secure) server with the specified endpoint and listen backlog. * <p> * The address of the {@code endpoint} can be used on a multi-homed host for a server that will only accept * connect requests to one of its addresses. If address of the {@code endpoint} is the wildcard address, it will * default accepting connections on any/all local addresses. * </p> * <p> * The port of the {@code endpoint} must be between 0 and 65535, inclusive. If it is zero, then an ephemeral port * will be picked for the server socket. *</p> * <p> * The {@code backlog} argument must be a positive value greater than 0. If the value passed if equal or less * than 0, then the default value will be assumed. * </p> * * @param endpoint The {@link InetAddress} and local port the server will bind to; {@link * InetSocketAddress#InetSocketAddress(int)} will accept connections on any/all local addresses; * port number zero will pick an ephemeral port * @param backlog The listen backlog */ public TcpServer(InetSocketAddress endpoint, int backlog, ConnectionHandler clientConnectionHandler) throws IOException { this(TcpServer.serverSocket(endpoint, backlog), clientConnectionHandler); }
/** * Creates a secure server with the specified endpoint and listen backlog. * <p> * The address of the {@code endpoint} can be used on a multi-homed host for a server that will only accept connect * requests to one of its addresses. If address of the {@code endpoint} is the wildcard address, it will default * accepting connections on any/all local addresses. * <p> * The port of the {@code endpoint} must be between 0 and 65535, inclusive. If it is zero, then an ephemoral port * will be picked for the server socket. * <p> * The {@code backlog} argument must be a positive value greater than 0. If the value passed if equal or less than * 0, then the default value will be assumed. * * @param endpoint The local port and {@link InetAddress} the server will bind to. If {@code null}, then the * system will pick up an ephemeral port and a valid local address to bind the socket. * @param backlog The listen backlog */ public TcpServer( InetSocketAddress endpoint, int backlog, SSLContext sslContext, ConnectionHandler clientConnectionHandler ) throws IOException { this(TcpServer.secureServerSocket(endpoint, backlog, sslContext), clientConnectionHandler); }
continue; } catch (SocketException se) { if (TcpServer.isSocketClosedException(se)) { LOGGER.log(FINE, "{0}: {1}", new Object[] { this.serverSocket, se }); return;
@Override public void stop() { this.tcpServer.stop(); } }
/** * Creates a (non-secure) server with the specified endpoint and listen backlog. * <p> * The address of the <var>endpoint</var> can be used on a multi-homed host for a server that will only accept * connect requests to one of its addresses. If address of the <var>endpoint</var> is the wildcard address, it * will default accepting connections on any/all local addresses. * </p> * <p> * The port of the <var>endpoint</var> must be between 0 and 65535, inclusive. If it is zero, then an ephemeral * port will be picked for the server socket. *</p> * <p> * The <var>backlog</var> argument must be a positive value greater than 0. If the value passed if equal or less * than 0, then the default value will be assumed. * </p> * * @param endpoint The {@link InetAddress} and local port the server will bind to; {@link * InetSocketAddress#InetSocketAddress(int)} will accept connections on any/all * local addresses; port number zero will pick an ephemeral port * @param backlog The listen backlog * @param clientConnectionHandler Is called exactly once for each accepted connection */ public TcpServer(InetSocketAddress endpoint, int backlog, ConnectionHandler clientConnectionHandler) throws IOException { this(TcpServer.serverSocket(endpoint, backlog), clientConnectionHandler); }
ConnectionHandler clientConnectionHandler ) throws IOException { this(TcpServer.secureServerSocket(endpoint, backlog, sslContext), clientConnectionHandler);
/** * This {@link HttpServer} will accept connections on the <var>endpoint</var> and will handle each with the * <var>httpClientConnectionHandler</var>. * * @param endpoint The {@link InetAddress} and local port the server will bind to; {@link * InetSocketAddress#InetSocketAddress(int)} will accept connections on any/all local addresses; * port number zero will pick an ephemeral port */ public HttpServer( InetSocketAddress endpoint, final HttpClientConnectionHandler httpClientConnectionHandler ) throws IOException { this.tcpServer = new TcpServer(endpoint, 0, httpClientConnectionHandler); }
/** * Will stop the accepting connections from the server socket, close the server socket, and cause {@link #run()} to * return as quickly as possible. */ @Override public void stop() { this.tcpServer.stop(); }
@Override public void run() throws IOException { this.tcpServer.run(); }
/** * The address and the <em>actual</em> port that this {@link Httpd} is bound to. * * @see #Httpd(InetSocketAddress, String) * @see TcpServer#getEndpointAddress() */ public InetSocketAddress getEndpointAddress() { return this.tcpServer.getEndpointAddress(); } }
/** * This {@link HttpServer} will accept secure (HTTPS) connections on the {@code endpoint} and will handle each * with the <var>httpClientConnectionHandler</var>. * * @param endpoint The {@link InetAddress} and local port the server will bind to; {@link * InetSocketAddress#InetSocketAddress(int)} will accept connections on any/all local addresses; * port number zero will pick an ephemeral port */ public HttpServer( InetSocketAddress endpoint, SSLContext sslContext, final HttpClientConnectionHandler httpClientConnectionHandler ) throws IOException { this.tcpServer = new TcpServer(endpoint, 0, sslContext, httpClientConnectionHandler); }
/** * Will stop the accepting connections from the server socket, close the server socket, and cause {@link #run()} to * return as quickly as possible. */ @Override public void stop() { this.tcpServer.stop(); }