An asynchronous channel for reading, writing, and manipulating a TCP socket.
On the JVM this is a wrapper around java.nio.channels.AsynchronousSocketChannel (class available since Java 7 for doing async I/O on sockets).
- Example
val asyncSocketChannel = AsyncSocketChannel() val connectF = asyncSocketChannel.connect(new InetSocketAddress("google.com", 80)) val bytes = ByteBuffer.wrap("Hello world!".getBytes("UTF-8")) val writeF = connectF.flatMap(_ => asyncSocketChannel.write(bytes, None)) writeF.onComplete { case Success(nr) => println(f"Bytes written: $nr%d") case Failure(exc) => println(s"ERR: $exc") }- Companion
- object
Value members
Abstract methods
Connects this channel.
Connects this channel.
- Value Params
- cb
is the callback to be called with the result, once this asynchronous operation is complete
- remote
the remote address to which this channel is to be connected
Asks the socket address that this channel's socket is bound to
Asks the socket address that this channel's socket is bound to
Reads a sequence of bytes from this channel into the given buffer
Reads a sequence of bytes from this channel into the given buffer
- Value Params
- cb
is the callback to be called with the result, once this asynchronous operation is complete . For this method it signals the number of bytes read or -1 if no bytes could be read because the channel has reached end-of-stream
- dst
is the buffer holding the bytes read on completion
- timeout
an optional maximum time for the I/O operation to complete
Asks the remote address to which this channel's socket is connected
Asks the remote address to which this channel's socket is connected
Indicates that this channel will not read more data - end-of-stream indication
Indicates that this channel will not read more data - end-of-stream indication
Indicates that this channel will not write more data - end-of-stream indication
Indicates that this channel will not write more data - end-of-stream indication
Writes a sequence of bytes to this channel from the given buffer
Writes a sequence of bytes to this channel from the given buffer
- Value Params
- cb
is the callback to be called with the result, once this asynchronous operation is complete . For this method it signals the number of bytes that were written
- src
is the buffer holding the sequence of bytes to write
- timeout
an optional maximum time for the I/O operation to complete
Concrete methods
Connects this channel.
Connects this channel.
- Value Params
- remote
the remote address to which this channel is to be connected
Reads a sequence of bytes from this channel into the given buffer
Reads a sequence of bytes from this channel into the given buffer
- Value Params
- dst
is the buffer holding the bytes read on completion
- timeout
an optional maximum time for the I/O operation to complete
- Returns
the number of bytes read or -1 if no bytes could be read because the channel has reached end-of-stream
Writes a sequence of bytes to this channel from the given buffer
Writes a sequence of bytes to this channel from the given buffer
- Value Params
- src
is the buffer holding the sequence of bytes to write
- timeout
an optional maximum time for the I/O operation to complete
- Returns
the number of bytes that were written