public class TCPClient
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
CONNECTED
State value
|
static java.lang.String |
CONNECTING
State value
|
static java.lang.String |
CONNECTION_FAILED
State value
|
static java.lang.String |
DISCONNECTED
State value
|
static java.lang.String |
MESSAGE
State value
|
static java.lang.String |
SERVER_OCCUPIED
State value
|
Constructor and Description |
---|
TCPClient(java.lang.String host,
int port)
Same, but isVerbose = false
|
TCPClient(java.lang.String host,
int port,
boolean isVerbose)
Creates a TCP socket client prepared for a connection with a
TCPServer at given address and port.
|
Modifier and Type | Method and Description |
---|---|
void |
addTCPClientListener(TCPClientListener listener)
Registers a TCPClientListener to get state change notifications.
|
boolean |
connect()
Same as connect(int timeout) with system default timeout.
|
boolean |
connect(int timeout)
Creates a connection to the server (blocking until timeout).
|
void |
disconnect()
Closes the connection with the server.
|
static java.lang.String |
getVersion()
Returns the library version.
|
boolean |
isConnected()
Returns true if client is connected to a server.
|
boolean |
isConnecting()
Returns true during a connection trial.
|
void |
sendMessage(java.lang.String msg)
Same as sendMessage(String msg, int responseTime) with responseTime = 0.
|
java.lang.String |
sendMessage(java.lang.String msg,
int responseTime)
Sends the information msg to the server (as String, the character \0
(ASCII 0) serves as end of string indicator, it is transparently added
and removed).
|
public static java.lang.String CONNECTING
public static java.lang.String SERVER_OCCUPIED
public static java.lang.String CONNECTION_FAILED
public static java.lang.String CONNECTED
public static java.lang.String DISCONNECTED
public static java.lang.String MESSAGE
public TCPClient(java.lang.String host, int port, boolean isVerbose)
host
- the IP address of the hostport
- the IP port where to listen (0..65535)isVerbose
- if true, debug messages are written to System.outpublic TCPClient(java.lang.String host, int port)
host
- the IP address of the hostport
- the IP port where to listen (0..65535)public void addTCPClientListener(TCPClientListener listener)
listener
- the listener to registerpublic boolean connect(int timeout)
timeout
- the maximum time (in s) for the connection trial (0: for default timeout)public boolean connect()
public boolean isConnecting()
public boolean isConnected()
public void disconnect()
public java.lang.String sendMessage(java.lang.String msg, int responseTime)
msg
- the message to sendresponseTime
- the maximum time to wait for a server reply (in s)public void sendMessage(java.lang.String msg)
msg
- the message to sendpublic static java.lang.String getVersion()