Fantom

 

const class

inet::TcpListener

sys::Obj
  inet::TcpListener

TcpListener is a server socket that listens to a local well known port for incoming TcpSockets.

Note: TcpListener is marked as a const class to give protocol developers the flexibility. However TcpListener is inherently thread unsafe - therefore it is the developers responsibility to use this API in a thread safe manner.

Slots

accept

TcpSocket accept()

Accept the next incoming connection. This method blocks the calling thread until a new connection is established. If this listener's receiveTimeout option is configured, then accept will timeout with an IOErr.

bind

native This bind(IpAddr? addr, Int? port, Int backlog := 50)

Bind this listener to the specified local address. If addr is null then the default IpAddr for the local host is selected. If port is null an ephemeral port is selected. Throw IOErr if the port is already bound or the bind fails. Return this.

close

native Bool close()

Close this server socket. This method is guaranteed to never throw an IOErr. Return true if the socket was closed successfully or false if the socket was closed abnormally.

isBound

native Bool isBound()

Is this socket bound to a local address and port.

isClosed

native Bool isClosed()

Is this socket closed.

localAddr

native IpAddr? localAddr()

Get the bound local address or null if unbound.

localPort

native Int? localPort()

Get the bound local port or null if unbound.

make

new make()

Make a new unbound TCP server socket.

options

SocketOptions options()

Access the SocketOptions used to tune this server socket. The following options apply to TcpListeners:

  • receiveBufferSize
  • reuseAddr
  • receiveTimeout Accessing other option fields will throw UnsupportedErr.