public class NioClient extends NioBaseServer implements Client
NioBaseServer.Acceptor
BaseServer.Reaper
Modifier and Type | Field and Description |
---|---|
protected NioConnection |
conn |
protected Address |
remote_addr |
acceptor, copy_on_partial_write, max_send_buffers, num_selects, reader_idle_time, reg_lock, registration, selector
client_bind_addr, client_bind_port, conn_expire_time, conn_listeners, conns, defer_client_binding, factory, linger, local_addr, log, reaper, reaperInterval, receiver, recv_buf_size, running, send_buf_size, sock_conn_timeout, sock_creation_lock, tcp_nodelay, time_service, use_peer_connections
Modifier | Constructor and Description |
---|---|
|
NioClient(java.net.InetAddress bind_addr,
int bind_port,
java.net.InetAddress server_addr,
int server_port)
Creates an instance of an
NioClient that acts as a client: no server channel is created and
no acceptor is started to listen for incoming connections. |
|
NioClient(IpAddress bind_addr,
IpAddress server_addr)
Creates an instance of an
NioClient that acts as a client: no server channel is created and
no acceptor is started to listen for incoming connections. |
protected |
NioClient(ThreadFactory thread_factory) |
Modifier and Type | Method and Description |
---|---|
boolean |
isConnected() |
boolean |
isOpen() |
Address |
remoteAddress() |
NioClient |
remoteAddress(IpAddress addr)
Sets the address of the server.
|
void |
send(Address dest,
byte[] data,
int offset,
int length) |
void |
send(Address dest,
java.nio.ByteBuffer data) |
void |
send(byte[] data,
int offset,
int length)
Sends data to the remote server.
|
void |
send(java.nio.ByteBuffer data)
Sends data to the remote server.
|
void |
start()
Starts accepting connections.
|
void |
stop()
Stops listening for connections and handling traffic.
|
java.lang.String |
toString() |
acceptorRunning, copyOnPartialWrite, copyOnPartialWrite, createConnection, handleAccept, maxSendBuffers, maxSendBuffers, numPartialWrites, numSelects, printBuffers, readerIdleTime, readerIdleTime, register, selectorOpen
addConnection, addConnectionListener, clearConnections, clientBindAddress, clientBindAddress, clientBindPort, clientBindPort, close, closeConnection, connectionClosed, connectionEstablished, connectionEstablishedTo, connExpireTime, connExpireTimeout, deferClientBinding, deferClientBinding, explanation, getConnection, getNumConnections, getNumOpenConnections, hasConnection, linger, linger, localAddress, localAddress, log, log, notifyConnectionClosed, notifyConnectionEstablished, printConnections, reaperInterval, reaperInterval, receive, receive, receiveBufferSize, receiveBufferSize, receiver, receiver, removeConnectionIfPresent, removeConnectionListener, replaceConnection, retainAll, running, sendBufferSize, sendBufferSize, sendToAll, sendToAll, socketConnectionTimeout, socketConnectionTimeout, tcpNodelay, tcpNodelay, timeService, timeService, usePeerConnections, usePeerConnections, validateArgs
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
localAddress
protected Address remote_addr
protected NioConnection conn
public NioClient(IpAddress bind_addr, IpAddress server_addr)
NioClient
that acts as a client: no server channel is created and
no acceptor is started to listen for incoming connections. Instead, a channel is created
(bound to bind_addr/bind_port) and connected to server_addr/server_port. This is used to send messages to the
remote server and receive messages from it. Note that there is only a single TCP connection established between
the client and server.bind_addr
- The address to which the local channel should bind to. Can be null, then the OS picks the addressserver_addr
- The address of the server to connect tojava.lang.Exception
- If the creation failedpublic NioClient(java.net.InetAddress bind_addr, int bind_port, java.net.InetAddress server_addr, int server_port)
NioClient
that acts as a client: no server channel is created and
no acceptor is started to listen for incoming connections. Instead, a channel is created
(bound to bind_addr/bind_port) and connected to server_addr/server_port. This is used to send messages to the
remote server and receive messages from it. Note that there is only a single TCP connection established between
the client and server.bind_addr
- The address to which the local channel should bind to. Can be null, then the OS picks the addressbind_port
- The local port. Can be 0, then the OS picks the port.server_addr
- The address of the server to connect toserver_port
- The port of the server to connect to.java.lang.Exception
- If the creation failedprotected NioClient(ThreadFactory thread_factory)
public Address remoteAddress()
remoteAddress
in interface Client
public NioClient remoteAddress(IpAddress addr)
public boolean isConnected()
isConnected
in interface Client
public void start() throws java.lang.Exception
BaseServer
start
in class BaseServer
java.lang.Exception
public void stop()
BaseServer
stop
in class BaseServer
public void send(Address dest, java.nio.ByteBuffer data) throws java.lang.Exception
send
in class BaseServer
java.lang.Exception
public void send(Address dest, byte[] data, int offset, int length) throws java.lang.Exception
send
in class BaseServer
java.lang.Exception
public void send(byte[] data, int offset, int length) throws java.lang.Exception
Client
public void send(java.nio.ByteBuffer data) throws java.lang.Exception
Client
public java.lang.String toString()
toString
in class BaseServer
Copyright © 1998-2020 Red Hat. All Rights Reserved.