![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
Next, you need a call to listen
; this call causes the server to
wait for a client to solicit a connection:
listen (socket_number, 5);
The first argument, again, is the socket descriptor established by the call
to socket
.
The second argument indicates how may clients are allowed in a queue
awaiting a socket connection with the server. In our example, there is to
be just one client, so the value of the second argument is not relevant.
In more complex situations, several clients may wish to establish a socket
connection to the same server. In such situations, the server initiates
action with the first client that announces itself after the call to
listen
, and until the server is ready to deal with other prospective
clients, those prospective clients are queued. Any clients that try to get
into the queue, after it is filled, are told that the server is
unavailable.
Most implementation require the second argument of listen
to be
between 1 and 5; many programmers habitually use 5, even if no more than
one socket is to be established by their server program.