Package

monix.nio

tcp

Permalink

package tcp

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. tcp
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. abstract class AsyncServerSocketChannel extends AutoCloseable

    Permalink

    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:
    1. 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")
      }
  2. abstract class AsyncSocketChannel extends AutoCloseable

    Permalink

    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:
    1. 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")
      }
  3. final class AsyncSocketChannelClient extends AnyRef

    Permalink

    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()

    returns

    an AsyncSocketChannelClient

  4. final class AsyncSocketChannelConsumer extends AsyncChannelConsumer

    Permalink

    A TCP socket Consumer that can be used to send data asynchronously from an Observable.

    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

  5. final class AsyncSocketChannelObservable extends AsyncChannelObservable

    Permalink

    A TCP socket Observable that can be subscribed to in order to read the incoming bytes asynchronously.

    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

  6. abstract class TaskServerSocketChannel extends AnyRef

    Permalink

    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:
    1. 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")
      })
  7. abstract class TaskSocketChannel extends AnyRef

    Permalink

    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:
    1. 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")
      })

Value Members

  1. object AsyncServerSocketChannel

    Permalink
  2. object AsyncSocketChannel

    Permalink
  3. object AsyncSocketChannelClient

    Permalink
  4. object TaskServerSocketChannel

    Permalink
  5. object TaskSocketChannel

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

    Permalink

    Creates a TCP server

    Creates a TCP server

    host

    hostname

    port

    TCP port number

    returns

    a bound TaskServerSocketChannel

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

    Permalink

    Returns a TCP socket Observable that can be subscribed to in order to read the incoming bytes asynchronously.

    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

    taskSocketChannel

    the underlying TaskSocketChannel

    bufferSize

    the size of the buffer used for reading

    returns

    an AsyncSocketChannelObservable

  8. def readAsync(host: String, port: Int, bufferSize: Int = 256 * 1024): AsyncSocketChannelObservable

    Permalink

    Returns a TCP socket Observable that can be subscribed to in order to read the incoming bytes asynchronously.

    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

    host

    hostname

    port

    TCP port number

    bufferSize

    the size of the buffer used for reading

    returns

    an AsyncSocketChannelObservable

  9. def readWriteAsync(taskSocketChannel: TaskSocketChannel, bufferSize: Int = 256 * 1024)(implicit scheduler: Scheduler): AsyncSocketChannelClient

    Permalink

    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()

    taskSocketChannel

    the underlying TaskSocketChannel

    bufferSize

    the size of the buffer used for reading

    returns

    an AsyncSocketChannelClient

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

    Permalink

    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()

    host

    hostname

    port

    TCP port number

    bufferSize

    the size of the buffer used for reading

    returns

    an AsyncSocketChannelClient

  11. def writeAsync(taskSocketChannel: TaskSocketChannel): AsyncSocketChannelConsumer

    Permalink

    Returns a TCP socket Consumer that can be used to send data asynchronously from an Observable.

    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

    taskSocketChannel

    the underlying TaskSocketChannel

    returns

    an AsyncSocketChannelConsumer

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

    Permalink

    Returns a TCP socket Consumer that can be used to send data asynchronously from an Observable.

    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

    host

    hostname

    port

    TCP port number

    returns

    an AsyncSocketChannelConsumer

Inherited from AnyRef

Inherited from Any

Ungrouped