public class BlockingClient extends java.lang.Object implements MessageWriteTarget
Creates a simple connection to a server using a StreamConnection to process data.
Generally, using NioClient and NioClientManager should be preferred over BlockingClient
and BlockingClientManager, unless you wish to connect over a proxy or use some other network settings that
cannot be set using NIO.
| Constructor and Description |
|---|
BlockingClient(java.net.SocketAddress serverAddress,
StreamConnection connection,
int connectTimeoutMillis,
javax.net.SocketFactory socketFactory,
java.util.Set<BlockingClient> clientSet)
Creates a new client to the given server address using the given
StreamConnection to decode the data. |
| Modifier and Type | Method and Description |
|---|---|
void |
closeConnection()
Closes the connection to the server, triggering the
StreamConnection.connectionClosed()
event on the network-handling thread where all callbacks occur. |
com.google.common.util.concurrent.ListenableFuture<java.net.SocketAddress> |
getConnectFuture()
Returns a future that completes once connection has occurred at the socket level or with an exception if failed to connect.
|
static void |
runReadLoop(java.io.InputStream stream,
StreamConnection connection)
A blocking call that never returns, except by throwing an exception.
|
com.google.common.util.concurrent.ListenableFuture |
writeBytes(byte[] message)
Writes the given bytes to the remote server.
|
public BlockingClient(java.net.SocketAddress serverAddress,
StreamConnection connection,
int connectTimeoutMillis,
javax.net.SocketFactory socketFactory,
@Nullable
java.util.Set<BlockingClient> clientSet)
throws java.io.IOException
Creates a new client to the given server address using the given StreamConnection to decode the data.
The given connection MUST be unique to this object. This does not block while waiting for the connection to
open, but will call either the StreamConnection.connectionOpened() or
StreamConnection.connectionClosed() callback on the created network event processing thread.
connectTimeoutMillis - The connect timeout set on the connection (in milliseconds). 0 is interpreted as no
timeout.socketFactory - An object that creates Socket objects on demand, which may be customised to control
how this client connects to the internet. If not sure, use SocketFactory.getDefault()clientSet - A set which this object will add itself to after initialization, and then remove itself fromjava.io.IOExceptionpublic static void runReadLoop(java.io.InputStream stream,
StreamConnection connection)
throws java.lang.Exception
StreamConnection, for example, a Peer.java.lang.Exceptionpublic void closeConnection()
StreamConnection.connectionClosed()
event on the network-handling thread where all callbacks occur.closeConnection in interface MessageWriteTargetpublic com.google.common.util.concurrent.ListenableFuture writeBytes(byte[] message)
throws java.io.IOException
MessageWriteTargetwriteBytes in interface MessageWriteTargetjava.io.IOExceptionpublic com.google.common.util.concurrent.ListenableFuture<java.net.SocketAddress> getConnectFuture()