Accepting A Connection - HP Rp3440-4 - 9000 - 0 MB RAM Programmer's Manual

Bsd sockets interface programmer’s guide
Hide thumbs Also See for Rp3440-4 - 9000 - 0 MB RAM:
Table of Contents

Advertisement

Using Internet Stream Sockets
Writing the Server Process
backlog is the preferred number of unaccepted incoming connections
allowed at a given time. The actual number may be greater than the
specified backlog. When the request is full, further connection requests
are rejected.
A backlog of 0 specifies only 1 pending connection can exist at any given
time. SOMAXCONN is defined in <sys/socket.h>. The default setting
is 20.
When to Set Up Server to Listen
The server process should be set up to listen after socket is created and
bound and before the server can respond to connection requests. Refer to
the listen(2) man page for more information on listen.

Accepting a Connection

The server process can accept any connection requests that enter its
queue after it executes listen. accept creates a new socket for the
connection and returns the socket descriptor for the new socket. The new
socket:
• Is created with the same properties as the old socket.
• Has the same bound port address as the old socket.
• Is connected to the client process's socket.
accept blocks until there is a connection request from a client process in
the queue, unless you are using nonblocking I/O. accept and its
parameters are described in the following table.
Include files:
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
System call:
s = accept(ls,addr,addrlen)
int s;
int ls;
struct sockaddr *addr;
int *addrlen;
38
Chapter 2

Advertisement

Table of Contents
loading

Table of Contents