[ Stream I/O | Reference Manual | Alphabetic Index ]

listen(+Stream, +Queue)

Specifies how many connections are accepted for a socket and makes connections available.
Stream handle or alias (atom)
An integer.


listen/2 is a direct link to the listen(2) socket system call. Stream must be a socket stream created with socket/3 of the type stream. Queue specifies the length of the connection queue, i.e. how many connections are allowed for this socket. After the call to listen/2, other processes can call connect/2 to connect with this socket, but the I/O is possible only after the server process creates the new socket using accept/3.

Stream sockets are connected using the standard sequence, i.e. socket/3, bind/2, listen/2 and accept/3 on the server and socket/3 and connect/2 on the client. After the sockets are connected, both processes can use them for reading and writing.

Modes and Determinism


(4) instantiation fault
Stream or Queue is not instantiated.
(5) type error
Stream is instantiated, but not to an atom or a stream handle.
(5) type error
Queue is instantiated but not to an integer.
(170) system interface error
It was not possible to execute the system call.


      socket(internet, stream, s), bind(s, Addr), listen(s, 1).

      listen(s, N)                  (Error 4).
      listen(s, 1.0)                (Error 5).
      listen(null, 2)               (Error 170).

See Also

socket / 3, bind / 2, accept / 3, connect / 2, new_socket_server / 3