public class TCPClient extends AbstractSelector
AbstractSelector
. This implementation
is purely non-blocking and can handle both PlainSocket
s and
SecureSocket
s.address, cipherSuits, container, context, isClient, logger, needClientAuth, pendingData, port, protocols, selector, singleThreaded, taskWorker, toWorker, usingSSL
Constructor and Description |
---|
TCPClient(java.net.InetAddress address,
int port,
AbstractPacketWorker packetWorker,
boolean usingSSL,
boolean needClientAuth)
Create a TCPClient instance
|
Modifier and Type | Method and Description |
---|---|
protected void |
accept(java.nio.channels.SelectionKey key)
As this is the client implementation, it is NOT allowed to call this
method which is only useful for server implementations.
|
protected void |
closeSocket(SocketIF socket)
This method overrides the default
AbstractSelector.closeSocket(SocketIF) method, to also stop this
client from running, as this client implementation only has one
associated SocketIF . |
protected void |
connect(java.nio.channels.SelectionKey key)
Finish the connection to the server.
|
protected void |
initConnection()
Initialize a client connection.
|
void |
invalidateSession()
Invalidate the SSL/TLS session (if any) on the underlying
SocketIF . |
boolean |
isConnected()
Returns whether or not this client is connected, if and only if it is
running (returns false otherwise).
|
void |
send(PacketIF packet)
|
addListener, handshakeComplete, invalidateSession, isRunning, read, removeListener, run, send, setRunning, setupEngine, setupSSL, taskComplete, timeoutExpired, write
public TCPClient(java.net.InetAddress address, int port, AbstractPacketWorker packetWorker, boolean usingSSL, boolean needClientAuth)
address
- The address to connect toport
- The port to connect topacketWorker
- The instance of packet worker to useusingSSL
- Whether we are using SSL/TLSneedClientAuth
- Whether this client should also authenticate with
the server.public void send(PacketIF packet)
PacketIF
over the this client's SocketIF
. Since
the client only has one socket, no socket parameter is necessary.packet
- The PacketIF to send through the associated SocketIF.AbstractSelector.send(ch.dermitza.securenio.socket.SocketIF,
java.nio.ByteBuffer)
public void invalidateSession()
SocketIF
. As this client implementation only has a single socket,
no parameter is needed.protected void initConnection() throws java.io.IOException
SocketChannel
, configures it to non-blocking, and registers it
with the underlying Selector
instance with an
OP_CONNECT SelectionKey
. If this client implementation is using
SSL/TLS, it also sets up the SSLEngine
, to be used.initConnection
in class AbstractSelector
java.io.IOException
- Propagates all underlying IOExceptions as thrown, to
be handled by the application layer.AbstractSelector.run()
protected void accept(java.nio.channels.SelectionKey key)
NoSuchMethodError
if it is called and
do nothing else.accept
in class AbstractSelector
key
- The selection key with the underlying SocketChannel
to
be acceptedAbstractSelector.run()
protected void connect(java.nio.channels.SelectionKey key)
SocketIF
is a secure
socket. Finally, after the connection has been established, the socket is
registered to the underlying Selector
, with a
SelectionKey
of OP_READ, signalling it is ready to read data.connect
in class AbstractSelector
key
- The selection key with the underlying SocketChannel
that needs a connection finalization.public boolean isConnected()
protected void closeSocket(SocketIF socket)
AbstractSelector.closeSocket(SocketIF)
method, to also stop this
client from running, as this client implementation only has one
associated SocketIF
.closeSocket
in class AbstractSelector
socket
- The SocketIF to be closedAbstractSelector.closeSocket(SocketIF)