Package org.bitcoinj.net
Class NioClient
- java.lang.Object
-
- org.bitcoinj.net.NioClient
-
- All Implemented Interfaces:
MessageWriteTarget
public class NioClient extends java.lang.Object implements MessageWriteTarget
Creates a simple connection to a server using aStreamConnection
to process data.
-
-
Constructor Summary
Constructors Constructor Description NioClient(java.net.SocketAddress serverAddress, StreamConnection parser, java.time.Duration connectTimeout)
Creates a new client to the given server address using the givenStreamConnection
to decode the data.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
closeConnection()
Closes the connection to the server, triggering theStreamConnection.connectionClosed()
event on the network-handling thread where all callbacks occur.ListenableCompletableFuture<java.lang.Void>
writeBytes(byte[] message)
Writes the given bytes to the remote server.
-
-
-
Constructor Detail
-
NioClient
public NioClient(java.net.SocketAddress serverAddress, StreamConnection parser, java.time.Duration connectTimeout) 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 theStreamConnection.connectionOpened()
orStreamConnection.connectionClosed()
callback on the created network event processing thread.- Parameters:
serverAddress
- socket address of the server to connect toparser
- parses data from the serverconnectTimeout
- timeout for establishing a connection to the server, or ZERO for no timeout- Throws:
java.io.IOException
-
-
Method Detail
-
closeConnection
public void closeConnection()
Description copied from interface:MessageWriteTarget
Closes the connection to the server, triggering theStreamConnection.connectionClosed()
event on the network-handling thread where all callbacks occur.- Specified by:
closeConnection
in interfaceMessageWriteTarget
-
writeBytes
public ListenableCompletableFuture<java.lang.Void> writeBytes(byte[] message) throws java.io.IOException
Description copied from interface:MessageWriteTarget
Writes the given bytes to the remote server. The returned future will complete when all bytes have been written to the OS network buffer.- Specified by:
writeBytes
in interfaceMessageWriteTarget
- Throws:
java.io.IOException
-
-