BSD Sockets Interface Programmer's Guide

Chapter 2 37
Using Internet Stream Sockets
Writing the Server Process
Example:
struct sockaddr_in myaddr;
...
bind (ls, &myaddr, sizeof(struct sockaddr_in));
When to Bind Socket Addresses
The server process should bind the socket address after the socket is
created and before any other BSD Sockets system calls. Refer to the
bind(2) man page for more information on bind.
Setting Up the Server to Wait for Connection
Requests
Once your server process has an address bound to it, it must call listen
to set up a queue that accepts incoming connection requests. The server
process then monitors the queue for requests (using select(2) or
accept ). The server process cannot respond to a connection request
until it has executed listen. listen and its parameters are described
in the following table.
Include files: none
System call: listen(s, backlog)
int s, backlog;
Function result: 0 if listen is successful, –1 if failure occurs.
Example:
listen (ls, 5);
Parameter Description of Contents INPUT Value
s socket descriptor of local
socket
server socket’s descriptor
backlog preferred maximum
number of connection
requests in the queue at
any time
size of queue (between 0
and SOMAXCONN)