public class TcpServer
extends java.lang.Object
After starting this server with start(), connections are available through
getNextStreamConnection().
| Constructor and Description |
|---|
TcpServer(int port,
int maxOpenedConnections)
Constructs a new instance of
TcpServer using environment's default socket factory. |
TcpServer(int port,
int maxOpenedConnections,
javax.net.ServerSocketFactory serverSocketFactory)
|
TcpServer(int port,
int maxOpenedConnections,
javax.net.ServerSocketFactory serverSocketFactory,
int timeout)
|
| Modifier and Type | Method and Description |
|---|---|
void |
addConnection(java.net.Socket connection)
Add a connection to the list of opened connections.
|
java.net.InetAddress |
getInetAddress() |
protected java.lang.String |
getName()
Returns the name of this TCPServer.
|
java.net.Socket |
getNextStreamConnection()
Get the next
Socket to process. |
int |
getPort() |
boolean |
isStopped()
Returns
true if the TcpServer is stopped. |
void |
start()
Starts the
TcpServer. |
void |
stop()
Stops the
TcpServer and closes the connection. |
protected void |
tooManyOpenConnections(java.net.Socket connection)
Called when a connection cannot be added to the buffer.
|
public TcpServer(int port,
int maxOpenedConnections)
TcpServer using environment's default socket factory.port - the port to use.maxOpenedConnections - the maximal number of simultaneously opened connections.public TcpServer(int port,
int maxOpenedConnections,
javax.net.ServerSocketFactory serverSocketFactory)
port - the port to use.maxOpenedConnections - the maximal number of simultaneously opened connections.serverSocketFactory - the ServerSocketFactory.public TcpServer(int port,
int maxOpenedConnections,
javax.net.ServerSocketFactory serverSocketFactory,
int timeout)
port - the port to use.maxOpenedConnections - the maximal number of simultaneously opened connections.serverSocketFactory - the ServerSocketFactory.timeout - the timeout of opened connections.Socket.setSoTimeout(int)public void start()
throws java.io.IOException
TcpServer. The TcpServer can be started only once. Calling this method while the
TcpServer is already running causes a IllegalStateException.java.io.IOException - if an error occurs during the creation of the socket.public void stop()
TcpServer and closes the connection.public void addConnection(java.net.Socket connection)
connection - Socket to addpublic java.net.Socket getNextStreamConnection()
Socket to process. Block until a new connection is available or server is stopped.public boolean isStopped()
true if the TcpServer is stopped.true if the TcpServer is stopped, false otherwiseprotected java.lang.String getName()
protected void tooManyOpenConnections(java.net.Socket connection)
connection - Socket that can not be addedpublic int getPort()
public java.net.InetAddress getInetAddress()