public interface NetClient
Multiple connections to different servers can be made using the same instance.
This client supports a configurable number of connection attempts and a configurable delay between attempts.
If an instance is instantiated from an event loop then the handlers of the instance will always be called on that same event loop. If an instance is instantiated from some other arbitrary Java thread then an event loop will be assigned to the instance and used when any of its handlers are called.
Instances cannot be used from worker verticles
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the client.
|
NetClient |
connect(int port,
Handler<NetSocket> connectCallback)
Attempt to open a connection to a server at the specific
port and host localhost
The connect is done asynchronously and on success, a
NetSocket instance is supplied via the connectHandler instance |
NetClient |
connect(int port,
java.lang.String host,
Handler<NetSocket> connectHandler)
Attempt to open a connection to a server at the specific
port and host . |
void |
exceptionHandler(Handler<java.lang.Exception> handler)
Set the exception handler.
|
java.lang.Integer |
getBossThreads() |
java.lang.Long |
getConnectTimeout() |
java.lang.String |
getKeyStorePassword() |
java.lang.String |
getKeyStorePath() |
java.lang.Integer |
getReceiveBufferSize() |
int |
getReconnectAttempts()
Get the number of reconnect attempts
|
long |
getReconnectInterval()
Get the reconnect interval, in milliseconds.
|
java.lang.Integer |
getSendBufferSize() |
java.lang.Integer |
getTrafficClass() |
java.lang.String |
getTrustStorePassword() |
java.lang.String |
getTrustStorePath() |
java.lang.Boolean |
isReuseAddress() |
java.lang.Boolean |
isSoLinger() |
boolean |
isSSL() |
java.lang.Boolean |
isTCPKeepAlive() |
java.lang.Boolean |
isTCPNoDelay() |
boolean |
isTrustAll() |
NetClient |
setBossThreads(int threads)
Set the number of boss threads to use.
|
NetClient |
setConnectTimeout(long timeout)
Set the connect timeout in milliseconds.
|
NetClient |
setKeyStorePassword(java.lang.String pwd)
Set the password for the SSL key store.
|
NetClient |
setKeyStorePath(java.lang.String path)
Set the path to the SSL key store.
|
NetClient |
setReceiveBufferSize(int size)
Set the TCP receive buffer size for connections created by this instance to
size in bytes. |
NetClient |
setReconnectAttempts(int attempts)
Set the number of reconnection attempts.
|
NetClient |
setReconnectInterval(long interval)
Set the reconnect interval, in milliseconds
|
NetClient |
setReuseAddress(boolean reuse)
Set the TCP reuseAddress setting for connections created by this instance to
reuse . |
NetClient |
setSendBufferSize(int size)
Set the TCP send buffer size for connections created by this instance to
size in bytes. |
NetClient |
setSoLinger(boolean linger)
Set the TCP soLinger setting for connections created by this instance to
linger . |
NetClient |
setSSL(boolean ssl)
If
ssl is true , this signifies that any connections will be SSL connections. |
NetClient |
setTCPKeepAlive(boolean keepAlive)
Set the TCP keepAlive setting for connections created by this instance to
keepAlive . |
NetClient |
setTCPNoDelay(boolean tcpNoDelay)
If
tcpNoDelay is set to true then Nagle's algorithm
will turned off for the TCP connections created by this instance. |
NetClient |
setTrafficClass(int trafficClass)
Set the TCP trafficClass setting for connections created by this instance to
trafficClass . |
NetClient |
setTrustAll(boolean trustAll)
If you want an SSL client to trust *all* server certificates rather than match them
against those in its trust store, you can set this to true.
|
NetClient |
setTrustStorePassword(java.lang.String pwd)
Set the password for the SSL trust store.
|
NetClient |
setTrustStorePath(java.lang.String path)
Set the path to the SSL trust store.
|
NetClient connect(int port, Handler<NetSocket> connectCallback)
port
and host localhost
The connect is done asynchronously and on success, a
NetSocket
instance is supplied via the connectHandler
instanceNetClient connect(int port, java.lang.String host, Handler<NetSocket> connectHandler)
port
and host
.
host
can be a valid host name or IP addresss. The connect is done asynchronously and on success, a
NetSocket
instance is supplied via the connectHandler
instancevoid close()
NetClient setReconnectAttempts(int attempts)
int getReconnectAttempts()
NetClient setReconnectInterval(long interval)
long getReconnectInterval()
void exceptionHandler(Handler<java.lang.Exception> handler)
handler
.
If no handler is supplied any exceptions will be printed to System.err
NetClient setSSL(boolean ssl)
ssl
is true
, this signifies that any connections will be SSL connections.NetClient setKeyStorePath(java.lang.String path)
setSSL(boolean)
has been set to true
.The SSL key store is a standard Java Key Store, and will contain the client certificate. Client certificates are only required if the server requests client authentication.
NetClient setKeyStorePassword(java.lang.String pwd)
setSSL(boolean)
has been set to true
.NetClient setTrustStorePath(java.lang.String path)
setSSL(boolean)
has been set to true
.
The trust store is a standard Java Key Store, and should contain the certificates of any servers that the client trusts.
If you wish the client to trust all server certificates you can use the setTrustAll(boolean)
method.
NetClient setTrustStorePassword(java.lang.String pwd)
setSSL(boolean)
has been set to true
.NetClient setTrustAll(boolean trustAll)
Use this with caution as you may be exposed to "main in the middle" attacks
trustAll
- Set to true if you want to trust all server certificatesNetClient setTCPNoDelay(boolean tcpNoDelay)
tcpNoDelay
is set to true
then Nagle's algorithm
will turned off for the TCP connections created by this instance.NetClient setSendBufferSize(int size)
size
in bytes.NetClient setReceiveBufferSize(int size)
size
in bytes.NetClient setTCPKeepAlive(boolean keepAlive)
keepAlive
.NetClient setReuseAddress(boolean reuse)
reuse
.NetClient setSoLinger(boolean linger)
linger
.NetClient setTrafficClass(int trafficClass)
trafficClass
.NetClient setConnectTimeout(long timeout)
NetClient setBossThreads(int threads)
java.lang.Boolean isTCPNoDelay()
java.lang.Integer getSendBufferSize()
java.lang.Integer getReceiveBufferSize()
java.lang.Boolean isTCPKeepAlive()
java.lang.Boolean isReuseAddress()
java.lang.Boolean isSoLinger()
java.lang.Integer getTrafficClass()
java.lang.Long getConnectTimeout()
java.lang.Integer getBossThreads()
boolean isSSL()
boolean isTrustAll()
java.lang.String getKeyStorePath()
java.lang.String getKeyStorePassword()
java.lang.String getTrustStorePath()
java.lang.String getTrustStorePassword()