Class TcpClient
java.lang.Object
org.jgroups.blocks.cs.BaseServer
org.jgroups.blocks.cs.TcpBaseServer
org.jgroups.blocks.cs.TcpClient
- All Implemented Interfaces:
Closeable, AutoCloseable, Client, ConnectionListener
Client for servers based on TCP
- Since:
- 3.6.5
- Author:
- Bela Ban
-
Nested Class Summary
Nested classes/interfaces inherited from class BaseServer
BaseServer.Reaper -
Field Summary
FieldsFields inherited from class TcpBaseServer
buffered_inputstream_size, buffered_outputstream_size, max_send_queue, non_blocking_sends, peer_addr_read_timeout, use_lock_to_sendFields inherited from class BaseServer
client_bind_addr, client_bind_port, conn_expire_time, conn_listeners, conns, defer_client_binding, factory, linger, local_addr, locks, log, log_details, max_length, reaper, reaperInterval, receiver, recv_buf_size, running, send_buf_size, sock_conn_timeout, socket_factory, tcp_nodelay, time_service, timer, use_peer_connections -
Constructor Summary
ConstructorsConstructorDescriptionTcpClient(InetAddress bind_addr, int bind_port, InetAddress server_addr, int server_port) Creates an instance of anTcpClientthat acts as a client: no server socket is created and no acceptor is started to listen for incoming connections.TcpClient(InetAddress bind_addr, int bind_port, InetAddress server_addr, int server_port, boolean vthreads) Creates an instance of anTcpClientthat acts as a client: no server socket is created and no acceptor is started to listen for incoming connections. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose(boolean graceful) voidconnectionClosed(Connection conn) protected voiddoStart()protected voiddoStop(boolean graceful) booleanremoteAddress(IpAddress addr) Sets the address of the server.voidsend(byte[] data, int offset, int length) Sends data to the remote server.voidsend(ByteBuffer buf) Sends data to the remote server.voidsend(ByteBuffer[] bufs) Sends data to the remote server.voidvoidsend(Address dest, ByteBuffer buf) voidstart()voidstop()Stops listening for connections and handling traffic.toString()Methods inherited from class TcpBaseServer
createConnection, getBufferedInputStreamSize, getBufferedOutputStreamSize, maxSendQueue, maxSendQueue, nonBlockingSends, nonBlockingSends, peerAddressReadTimeout, peerAddressReadTimeout, setBufferedInputStreamSize, setBufferedOutputStreamSize, useLockToSend, useLockToSendMethods inherited from class BaseServer
addConnectionListener, clearConnections, clearConnections, clientBindAddress, clientBindAddress, clientBindPort, clientBindPort, close, closeConnection, closeConnection, closeConnection, closeConnection, connected, connectionEstablished, connectionEstablishedTo, connExpireTime, connExpireTimeout, deferClientBinding, deferClientBinding, explanation, flush, flushAll, forAllConnections, getConnection, getLock, getMaxLength, getNumConnections, getNumOpenConnections, handleIncomingConnection, handleOutgoingConnection, hasConnection, linger, linger, localAddress, localAddress, log, log, logDetails, logDetails, notifyConnectionClosed, notifyConnectionEstablished, printConnections, reaperInterval, reaperInterval, receive, receive, receive, receiveBufferSize, receiveBufferSize, receiver, receiver, removeConnectionIfPresent, removeConnectionListener, replaceConnection, retainAll, retainAll, running, sendBufferSize, sendBufferSize, sendToAll, sendToAll, setMaxLength, socketConnectionTimeout, socketConnectionTimeout, socketFactory, socketFactory, tcpNodelay, tcpNodelay, timer, timer, timeService, timeService, toString, useAcks, useAcks, usePeerConnections, usePeerConnections, validateArgsMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Client
localAddressMethods inherited from interface ConnectionListener
connectionEstablished
-
Field Details
-
remote_addr
-
conn
-
-
Constructor Details
-
TcpClient
Creates an instance of anTcpClientthat 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.- Parameters:
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 to
-
TcpClient
Creates an instance of anTcpClientthat 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.- Parameters:
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.
-
TcpClient
public TcpClient(InetAddress bind_addr, int bind_port, InetAddress server_addr, int server_port, boolean vthreads)
-
-
Method Details
-
remoteAddress
- Specified by:
remoteAddressin interfaceClient
-
remoteAddress
-
isConnected
public boolean isConnected()- Specified by:
isConnectedin interfaceClient
-
start
- Overrides:
startin classBaseServer- Throws:
Exception
-
stop
public void stop()Description copied from class:BaseServerStops listening for connections and handling traffic. Typically, socket handler or selector threads are stopped, and server sockets or channels are closed.- Overrides:
stopin classBaseServer
-
close
- Throws:
IOException
-
send
- Overrides:
sendin classBaseServer- Throws:
Exception
-
send
- Overrides:
sendin classBaseServer- Throws:
Exception
-
send
-
send
-
send
-
connectionClosed
- Specified by:
connectionClosedin interfaceConnectionListener- Overrides:
connectionClosedin classBaseServer
-
toString
- Overrides:
toStringin classBaseServer
-
doStart
-
doStop
protected void doStop(boolean graceful)
-