public class TCPServer
extends java.lang.Thread
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
CONNECTED
State value
|
static java.lang.String |
LISTENING
State value
|
static java.lang.String |
MESSAGE
State value
|
static java.lang.String |
PORT_IN_USE
State value
|
static java.lang.String |
TERMINATED
State value
|
Constructor and Description |
---|
TCPServer(int port)
Same with isVerbose = false.
|
TCPServer(int port,
boolean isVerbose)
Creates a TCP socket server that listens on TCP port
for a connecting client.
|
Modifier and Type | Method and Description |
---|---|
void |
addTCPServerListener(TCPServerListener listener)
Registers a TCPServerListener to get state change notifications.
|
void |
disconnect()
Closes the connection with the client and enters
the LISTENING state.
|
static java.lang.String |
getVersion()
Returns the library version.
|
boolean |
isConnected()
Returns true, if a client is connected to the server.
|
boolean |
isTerminated()
Returns true, if the server is in TERMINATED state.
|
void |
run()
For internal use only
|
void |
sendMessage(java.lang.String msg)
Sends the information msg to the client (as String, the character \0 (ASCII 0) serves as end of
string indicator, it is transparently added and removed)
|
void |
terminate()
Closes the connection and terminates the server thread.
|
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, toString, yield
public static java.lang.String PORT_IN_USE
public static java.lang.String CONNECTED
public static java.lang.String LISTENING
public static java.lang.String TERMINATED
public static java.lang.String MESSAGE
public TCPServer(int port, boolean isVerbose)
port
- the IP port where to listen (0..65535)isVerbose
- if true, debug messages are written to System.outpublic TCPServer(int port)
port
- the IP port where to listen (0..65535)public void run()
run
in interface java.lang.Runnable
run
in class java.lang.Thread
public void addTCPServerListener(TCPServerListener listener)
listener
- the listener to registerpublic boolean isConnected()
public void disconnect()
public void terminate()
public boolean isTerminated()
public void sendMessage(java.lang.String msg)
msg
- the message to sendpublic static java.lang.String getVersion()