AsyncServerSocketChannel

abstract class AsyncServerSocketChannel extends AutoCloseable

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
trait AutoCloseable
class Object
trait Matchable
class Any

Value members

Abstract methods

def accept(cb: Callback[Throwable, AsyncSocketChannel]): Unit

Accepts a connection

Accepts a connection

Value Params
cb

is the callback to be called with the result, once this asynchronous operation is complete

def bind(local: InetSocketAddress, backlog: Int): Unit

Binds the channel's socket to a local address and configures the socket to listen for connections

Binds the channel's socket to a local address and configures the socket to listen for connections

Value Params
backlog

the maximum number of pending connections. If the backlog parameter has the value 0, or a negative value, then an implementation specific default is used.

local

the local address to bind the socket, or null to bind to an automatically assigned socket address

def localAddress(): Option[InetSocketAddress]

Asks the socket address that this channel's socket is bound to

Asks the socket address that this channel's socket is bound to

Concrete methods

def accept(): Future[AsyncSocketChannel]

Accepts a connection

Accepts a connection

Inherited methods

@throws(java.lang.Exception)
def close(): Unit
Inherited from
AutoCloseable