public class TcpClient extends Object implements AutoCloseable
Modifier and Type | Class and Description |
---|---|
static class |
TcpClient.Conf
Configuration for
TcpClient |
Constructor and Description |
---|
TcpClient(TcpClient.Conf conf)
Create a TcpClient.
|
Instance Methods | |
---|---|
Async<TcpChannel> |
connect(String peerHost,
InetAddress ip,
int port)
Connect to a remote server.
|
int |
getConnectionCount()
Get the number of established connections.
|
void |
close()
Close the client and free resources.
|
Executor |
getExecutor()
Get the executor associated with the selector thread.
|
public TcpClient(TcpClient.Conf conf) throws Exception
Exception
public Async<TcpChannel> connect(String peerHost, InetAddress ip, int port)
This action succeeds when a TcpChannel is established and ready to read/write.
The default timeout is probably too long; the caller should set a reasonable timeout by
client.connect(peerHost, ip, port).timeout(duration)
The `peerHost` argument will become the TcpChannel's
peerHost
; it can be null.
public int getConnectionCount()
public void close()
All existing connections will be forcefully closed.
close
in interface AutoCloseable
public Executor getExecutor()
Tasks submitted to the executor will be executed on the selector thread, and executed sequentially in the order they are submitted.