A Task based 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 taskSocketChannel = TaskSocketChannel() val writeT = for { _ <- taskSocketChannel.connect(new InetSocketAddress("google.com", 80)) written <- taskSocketChannel.write(ByteBuffer.wrap("Hello world!".getBytes("UTF-8")), None) } yield { written } writeT.runAsync(new Callback[Int] { override def onSuccess(value: Int): Unit = println(f"Bytes written: $value%d") override def onError(ex: Throwable): Unit = println(s"ERR: $ex") })- Companion
- object
Value members
Concrete methods
Connects this channel.
Connects this channel.
- Value Params
- 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
- 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
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
- 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