Skip to content
Search

C:listen

lastmod 2018-08-17created 2016-12-271 edits

Creates a connection queue(:12) for a socket(:12).

Syntax

#include <sys/socket.h>
int listen(int s, int backlog);

Remarks

A server(:12)-side program uses the socket(2) function to create a listening socket that will accept connections from clients(:12). Client connections are made through the listening socket(:12): the client calls connect(2) to try to connect to the server, and if the 3-way:::handshake(:12) succeeds, a full connection with the server is established.

The established connection goes into a queue(:12), and only when the server side calls accept(2) does the server create a connected socket and communicate with the client using that connected socket(:12).

The listen(2) system call(:12) is used only for SOCK_STREAM and SOCK_SEQPACKET.

a is the listening socket created by socket(2). backlog is the number of connections that can wait in the queue. If a new connection is attempted while the backlog is full, the client will receive an ECONNREFUSED error. If a protocol that supports retransmission is used, the error is ignored and the connection is retried until it succeeds.

See also

Favorite site

References


  1. Joinc_-Linux_man-_listen.pdf ↩