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.
|
protected java.lang.String |
getName()
Returns the name of this TCPServer.
|
java.net.Socket |
getNextStreamConnection()
Get the next
Socket to process. |
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 added