public class TcpServer
extends java.lang.Thread
implements java.io.Closeable
| Modifier and Type | Field and Description |
|---|---|
protected ConnectionListener |
listener |
protected java.util.logging.Logger |
log |
protected int |
port |
protected java.net.ServerSocket |
sock |
| Constructor and Description |
|---|
TcpServer(int port,
ConnectionListener listener)
Create a TCP server running on a specified port.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Shutdown the TCP server.
|
int |
getPort()
Get the TCP port on which the server listens for connections.
|
void |
run() |
java.lang.String |
toString() |
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, yieldprotected int port
protected java.net.ServerSocket sock
protected ConnectionListener listener
protected java.util.logging.Logger log
public TcpServer(int port,
ConnectionListener listener)
port - TCP port number (0 to autoselect).public int getPort()
public void close()
close in interface java.io.Closeableclose in interface java.lang.AutoCloseablepublic void run()
run in interface java.lang.Runnablerun in class java.lang.Threadpublic java.lang.String toString()
toString in class java.lang.Thread