|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectde.unkrig.commons.net.TcpServer
public class TcpServer
A runnable that accepts TCP connections on a given interface/port and passes them to a TcpServer.ConnectionHandler.
Supports SSL.
Notice that this implementation does not use java.nio.channels, i.e. connections are handled
synchronously and each blocks one thread. In other words, it does not scale well for thousands of client
connections; consider using NioTcpServer for that use case.
| Nested Class Summary | |
|---|---|
static interface |
TcpServer.ConnectionHandler
Represents a TCP connection to a remote peer (e.g. a server or a client). |
| Constructor Summary | |
|---|---|
TcpServer(java.net.InetSocketAddress endpoint,
int backlog,
java.io.File keyStoreFile,
char[] keyStorePassword,
java.lang.String serverAlias,
TcpServer.ConnectionHandler clientConnectionHandler)
Create a secure server with the specified endpoint and listen backlog. |
|
TcpServer(java.net.InetSocketAddress endpoint,
int backlog,
TcpServer.ConnectionHandler clientConnectionHandler)
Create a server with the specified endpoint and listen backlog. |
|
| Method Summary | |
|---|---|
java.net.InetSocketAddress |
getEndpointAddress()
Returns the address and port of the actual endpoint, which may differ from the endpoint given to TcpServer(InetSocketAddress, int, ConnectionHandler) |
void |
run()
"To run" an instance means to call this method and wait until it returns. |
void |
stop()
Returns when this Stoppable has completely stopped. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public TcpServer(java.net.InetSocketAddress endpoint,
int backlog,
TcpServer.ConnectionHandler clientConnectionHandler)
throws java.io.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 backlog
java.io.IOException
public TcpServer(java.net.InetSocketAddress endpoint,
int backlog,
@Nullable
java.io.File keyStoreFile,
@Nullable
char[] keyStorePassword,
@Nullable
java.lang.String serverAlias,
TcpServer.ConnectionHandler clientConnectionHandler)
throws java.io.IOException,
java.security.KeyStoreException,
java.security.NoSuchAlgorithmException,
java.security.cert.CertificateException,
java.security.UnrecoverableKeyException,
java.security.KeyManagementException
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 backlog
java.io.IOException
java.security.KeyStoreException
java.security.NoSuchAlgorithmException
java.security.cert.CertificateException
java.security.UnrecoverableKeyException
java.security.KeyManagementException| Method Detail |
|---|
public java.net.InetSocketAddress getEndpointAddress()
TcpServer(InetSocketAddress, int, ConnectionHandler)
public void run()
throws java.io.IOException
RunnableWhichThrows
run in interface RunnableWhichThrows<java.io.IOException>java.io.IOExceptionpublic void stop()
StoppableStoppable has completely stopped.
stop in interface Stoppable
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||