public class TcpClient extends TcpBaseServer implements Client, ConnectionListener
BaseServer.Reaper
Modifier and Type | Field and Description |
---|---|
protected TcpConnection |
conn |
protected Address |
remote_addr |
peer_addr_read_timeout, send_queue_size, socket_factory, use_send_queues
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 |
---|---|
|
TcpClient(java.net.InetAddress bind_addr,
int bind_port,
java.net.InetAddress server_addr,
int server_port)
Creates an instance of an
TcpClient that acts as a client: no server socket is created and
no acceptor is started to listen for incoming connections. |
|
TcpClient(IpAddress bind_addr,
IpAddress server_addr)
Creates an instance of an
TcpClient that acts as a client: no server socket is created and
no acceptor is started to listen for incoming connections. |
protected |
TcpClient(ThreadFactory thread_factory,
SocketFactory socket_factory) |
Modifier and Type | Method and Description |
---|---|
void |
connectionClosed(Connection conn,
java.lang.String cause) |
void |
connectionEstablished(Connection conn) |
boolean |
isConnected() |
boolean |
isOpen() |
Address |
remoteAddress() |
TcpClient |
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() |
createConnection, peerAddressReadTimeout, peerAddressReadTimeout, sendQueueSize, sendQueueSize, socketFactory, socketFactory, useSendQueues, useSendQueues
addConnection, addConnectionListener, clearConnections, clientBindAddress, clientBindAddress, clientBindPort, clientBindPort, close, closeConnection, 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 TcpConnection conn
public TcpClient(IpAddress bind_addr, IpAddress server_addr)
TcpClient
that acts as a client: no server socket is created and
no acceptor is started to listen for incoming connections. Instead, a client socket 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 socket 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 TcpClient(java.net.InetAddress bind_addr, int bind_port, java.net.InetAddress server_addr, int server_port)
TcpClient
that acts as a client: no server socket is created and
no acceptor is started to listen for incoming connections. Instead, a client socket 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 socket 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 TcpClient(ThreadFactory thread_factory, SocketFactory socket_factory)
public Address remoteAddress()
remoteAddress
in interface Client
public TcpClient 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, byte[] data, int offset, int length) throws java.lang.Exception
send
in class BaseServer
java.lang.Exception
public void send(Address dest, java.nio.ByteBuffer data) 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 void connectionClosed(Connection conn, java.lang.String cause)
connectionClosed
in interface ConnectionListener
connectionClosed
in class BaseServer
public void connectionEstablished(Connection conn)
connectionEstablished
in interface ConnectionListener
connectionEstablished
in class BaseServer
public java.lang.String toString()
toString
in class BaseServer
Copyright © 1998-2020 Red Hat. All Rights Reserved.