monix.nio.tcp

Type members

Classlikes

abstract class AsyncServerSocketChannel extends AutoCloseable

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
abstract class AsyncSocketChannel extends AutoCloseable

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
Companion
class
final class AsyncSocketChannelClient(host: String, port: Int, bufferSize: Int)(implicit scheduler: Scheduler)

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

an AsyncSocketChannelClient

Companion
object
final class AsyncSocketChannelConsumer extends AsyncChannelConsumer

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

final class AsyncSocketChannelObservable extends AsyncChannelObservable

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
abstract class TaskSocketChannel

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
Companion
class

Value members

Concrete methods

def asyncServer(host: String, port: Int)(implicit scheduler: Scheduler): Task[TaskServerSocketChannel]

Creates a TCP server

Creates a TCP server

Value Params
host

hostname

port

TCP port number

Returns

a bound TaskServerSocketChannel

def readAsync(host: String, port: Int, bufferSize: Int): AsyncSocketChannelObservable

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

an AsyncSocketChannelObservable

def readAsync(taskSocketChannel: TaskSocketChannel, bufferSize: Int): AsyncSocketChannelObservable

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

an AsyncSocketChannelObservable

def readWriteAsync(host: String, port: Int, bufferSize: Int)(implicit scheduler: Scheduler): AsyncSocketChannelClient

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

an AsyncSocketChannelClient

def readWriteAsync(taskSocketChannel: TaskSocketChannel, bufferSize: Int)(implicit scheduler: Scheduler): AsyncSocketChannelClient

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

an AsyncSocketChannelClient

def writeAsync(host: String, port: Int): AsyncSocketChannelConsumer

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

an AsyncSocketChannelConsumer

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

an AsyncSocketChannelConsumer