public class NioTcpServer extends Object implements Stoppable
NioTcpServer.ConnectionHandler.
Does not supprt SSL (yet).
This implementation, opposed to TcpServer, does use java.nio.channels, i.e. connections are
handled asynchronously and do not block one thread each. In other words, it scales well for thousands of
client connections.
| Modifier and Type | Class and Description |
|---|---|
static interface |
NioTcpServer.ConnectionHandler
Represents a TCP connection to a remote peer (e.g. a server or a client).
|
| Constructor and Description |
|---|
NioTcpServer() |
| Modifier and Type | Method and Description |
|---|---|
InetSocketAddress |
addServer(InetSocketAddress endpoint,
int backlog,
NioTcpServer.ConnectionHandler clientConnectionHandler)
Create a server with the specified endpoint and listen backlog.
|
void |
start(int multiplexerThreadCount)
Starts this server.
|
void |
stop() |
public InetSocketAddress addServer(InetSocketAddress endpoint, int backlog, NioTcpServer.ConnectionHandler clientConnectionHandler) throws IOException
The address of the 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 endpoint is the wildcard address, it will default
accepting connections on any/all local addresses.
The port of the endpoint must be between 0 and 65535, inclusive. If it is zero, then an ephemoral port
will be picked for the server socket.
The 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.
endpoint - The local port and InetAddress the server will bind to. If null, then the
system will pick up an ephemeral port and a valid local address to bind the socket.backlog - The listen backlogIOExceptionpublic void start(int multiplexerThreadCount)
multiplexerThreadCount - Number of threads accepting connections. Notice that accepted connections
are handled by additional threads, so a value of 1 is appropriate in many
cases.Copyright © 2016 Arno Unkrig. All rights reserved.