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

accept(+Stream, -From, ?NewStream)

Accepts a connection for a stream socket and creates a new socket which can be used for I/O.
Stream handle or alias (atom)
A term unifiable with a structure atom/integer.
Atom, structure or variable.


accept/3 is a direct link to the accept(2) socket system call. Stream must be a socket stream created with socket/3 or new_socket_server/3 of the type stream, listening for connections. accept/3 blocks until there is a connection request from another process, and then it creates a new socket stream NewStream with the same properties as Stream, which can be then used for communication with the connecting process. The Stream socket remains open and listening for further connections.

In the internet domain, From is unified with the address of the connecting process in the form HostName/Port. In the unix domain, From is unified with an empty atom ''.

When instantiated, NewStream must be a symbolic stream name, i.e. an atom. The stream can also be specified as sigio(NewStream). In this case the socket is created and in addition it is instructed to send the signal io each time new data appears in it.

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 is not instantiated.
(5) type error
Stream is instantiated, but not to an atom or a sigio/1 structure.
(5) type error
From is instantiated but not to an atom or a structure.
(170) system interface error
It was not possible to execute the system call.


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

      accept(s, From, 6)            (Error 5).
      socket(internet, datagram, s), bind(s, Addr), listen(s, 2),
      accept(s, From, news)         (Error 170).

See Also

socket / 3, bind / 2, listen / 2, connect / 2