monix.nio.tcp
Type members
Classlikes
An asynchronous channel for stream-oriented listening sockets.
An asynchronous channel for stream-oriented listening sockets.
On the JVM this is a wrapper around java.nio.channels.AsynchronousServerSocketChannel (class available since Java 7 for doing async I/O on sockets).
- Example
val server = AsyncServerSocketChannel() server.bind(new InetSocketAddress(InetAddress.getByName(null), 9000)) val bytes = ByteBuffer.wrap("Hello world!".getBytes("UTF-8")) val writeF = server .accept() .flatMap { conn => val writeF0 = conn.write(bytes, None) conn.stopWriting() writeF0 } .map { sentLen => server.close() sentLen } writeF.onComplete { case Success(nr) => println(f"Bytes sent: $nr%d") case Failure(exc) => println(s"ERR: $exc") }- Companion
- object
An asynchronous channel for reading, writing, and manipulating a TCP socket.
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
A TCP client composed of an async reader(AsyncSocketChannelObservable) and an async writer(AsyncSocketChannelConsumer) pair that both use the same underlying socket that is not released automatically.
A TCP client composed of an async reader(AsyncSocketChannelObservable) and an async writer(AsyncSocketChannelConsumer) pair that both use the same underlying socket that is not released automatically.
In order to release the connection use close()
- Value Params
- bufferSize
the size of the buffer used for reading
- host
hostname
- port
TCP port number
- Returns
- Companion
- object
A TCP socket Consumer that can be used to send data asynchronously from an Observable. The underlying socket will be closed when the Observable ends
A TCP socket Consumer that can be used to send data asynchronously from an Observable. The underlying socket will be closed when the Observable ends
- Value Params
- host
hostname
- port
TCP port number
A TCP socket Observable that can be subscribed to
in order to read the incoming bytes asynchronously.
The underlying socket is closed on end-of-stream, on signalling Stop
after subscription or by cancelling it directly
A TCP socket Observable that can be subscribed to
in order to read the incoming bytes asynchronously.
The underlying socket is closed on end-of-stream, on signalling Stop
after subscription or by cancelling it directly
- Value Params
- bufferSize
the size of the buffer used for reading
- host
hostname
- port
TCP port number
A Task based asynchronous channel for stream-oriented listening sockets.
A Task based asynchronous channel for stream-oriented listening sockets.
On the JVM this is a wrapper around java.nio.channels.AsynchronousServerSocketChannel (class available since Java 7 for doing async I/O on sockets).
- Example
val server = TaskServerSocketChannel() val writeT = for { _ <- server.bind(new InetSocketAddress(InetAddress.getByName(null), 9000)) conn <- server.accept() written <- conn.writeL(java.nio.ByteBuffer.wrap("Hello world!".getBytes)) _ <- Task.eval(conn.stopWriting()) _ <- server.close() } yield { written } writeT.runAsync(new Callback[Int] { override def onError(ex: Throwable) = println(ex) override def onSuccess(value: Int) = println(f"Bytes sent: $value%d") })- Companion
- object
A Task based asynchronous channel for reading, writing, and manipulating a TCP socket.
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
Creates a TCP server
Creates a TCP server
- Value Params
- host
hostname
- port
TCP port number
- Returns
a bound TaskServerSocketChannel
Returns a TCP socket Observable that can be subscribed to in order to read the incoming bytes asynchronously. It will close the socket on end-of-stream, signalling Stop after subscription or by cancelling it directly
Returns a TCP socket Observable that can be subscribed to in order to read the incoming bytes asynchronously. It will close the socket on end-of-stream, signalling Stop after subscription or by cancelling it directly
- Value Params
- bufferSize
the size of the buffer used for reading
- host
hostname
- port
TCP port number
- Returns
Returns a TCP socket Observable that can be subscribed to in order to read the incoming bytes asynchronously. It will close the socket on end-of-stream, signalling Stop after subscription or by cancelling it directly
Returns a TCP socket Observable that can be subscribed to in order to read the incoming bytes asynchronously. It will close the socket on end-of-stream, signalling Stop after subscription or by cancelling it directly
- Value Params
- bufferSize
the size of the buffer used for reading
- taskSocketChannel
the underlying TaskSocketChannel
- Returns
Creates a TCP client - an async reader(AsyncSocketChannelObservable) and an async writer(AsyncSocketChannelConsumer) pair that both use the same underlying socket that is not released automatically.
Creates a TCP client - an async reader(AsyncSocketChannelObservable) and an async writer(AsyncSocketChannelConsumer) pair that both use the same underlying socket that is not released automatically.
In order to release the connection use close()
- Value Params
- bufferSize
the size of the buffer used for reading
- host
hostname
- port
TCP port number
- Returns
Creates a TCP client - an async reader(AsyncSocketChannelObservable) and an async writer(AsyncSocketChannelConsumer) pair that both use the same underlying socket that is not released automatically.
Creates a TCP client - an async reader(AsyncSocketChannelObservable) and an async writer(AsyncSocketChannelConsumer) pair that both use the same underlying socket that is not released automatically.
In order to release the connection use close()
- Value Params
- bufferSize
the size of the buffer used for reading
- taskSocketChannel
the underlying TaskSocketChannel
- Returns
Returns a TCP socket Consumer that can be used to send data asynchronously from an Observable. The underlying socket will be closed when the Observable ends
Returns a TCP socket Consumer that can be used to send data asynchronously from an Observable. The underlying socket will be closed when the Observable ends
- Value Params
- host
hostname
- port
TCP port number
- Returns
Returns a TCP socket Consumer that can be used to send data asynchronously from an Observable. The underlying socket will be closed when the Observable ends
Returns a TCP socket Consumer that can be used to send data asynchronously from an Observable. The underlying socket will be closed when the Observable ends
- Value Params
- taskSocketChannel
the underlying TaskSocketChannel
- Returns