java.lang.AutoCloseable, java.lang.Runnablepublic class TcpClient
extends java.lang.Object
implements java.lang.AutoCloseable, java.lang.Runnable
| Constructor | Description |
|---|---|
TcpClient(java.lang.String host,
int port) |
Creates a new
TcpClient bound to the specified host and port |
TcpClient(java.lang.String host,
int port,
boolean connectImmediately) |
Creates a new
TcpClient bound to the specified host and port |
| Modifier and Type | Method | Description |
|---|---|---|
void |
addCommandListener(CommandListener listener) |
|
void |
addMessageListener(MessageListener listener) |
|
void |
close() |
Attempts to gracefully-ish disconnect from the server that the client is connected to
|
java.util.concurrent.CompletableFuture<java.lang.Void> |
connect() |
Attempts to connect the client to the server specified when
creating the client object
|
java.util.Optional<ClientConnection> |
getConnection() |
|
void |
removeAllListeners() |
|
void |
removeCommandListener(CommandListener listener) |
|
void |
removeMessageListener(MessageListener listener) |
|
void |
run() |
|
void |
sendCommand(java.lang.String command,
java.lang.String arguments) |
Attempts to format, encrypt, and send the
command and
arguments to the server that the client is currently
connected to |
void |
sendText(java.lang.String data) |
Attempts to encrypt and send the
data to the server
that the client is currently connected to |
public TcpClient(java.lang.String host,
int port)
TcpClient bound to the specified host and porthost - the host name, or null for the loopback address.port - the port number.public TcpClient(java.lang.String host,
int port,
boolean connectImmediately)
throws ClientException
TcpClient bound to the specified host and porthost - the address of the serverport - the port the client should try to connect to the server throughconnectImmediately - true if you want the client to automatically connect to the serverClientExceptionpublic java.util.concurrent.CompletableFuture<java.lang.Void> connect()
throws ClientException
ClientException - if the client failed to create a
secure connection with the serverpublic void addMessageListener(MessageListener listener)
public void removeMessageListener(MessageListener listener)
public void addCommandListener(CommandListener listener)
public void removeCommandListener(CommandListener listener)
public void removeAllListeners()
public java.util.Optional<ClientConnection> getConnection()
public void run()
run in interface java.lang.Runnablepublic void sendText(java.lang.String data)
throws ClientException
data to the server
that the client is currently connected todata - the String to be sent to the serverClientException - if something went wrong while trying
to send the messagejava.lang.IllegalArgumentException - if data is nullpublic void sendCommand(java.lang.String command,
java.lang.String arguments)
throws ClientException
command and
arguments to the server that the client is currently
connected tocommand - arguments - ClientException - if something went wrong while trying
to send the messagepublic void close()
close in interface java.lang.AutoCloseable