HP Rp3440-4 - 9000 - 0 MB RAM Programmer's Manual page 39

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

Advertisement

Parameter
Contents
ls
socket
descriptor of
local socket
addr
socket address
addrlen
length of
address
Function result: socket descriptor of new socket if accept is successful,
–1 if failure occurs.
Example:
struct sockaddr_in peeraddr;
...
addrlen = sizeof(sockaddr_in);
s = accept (ls, &peeraddr, &addrlen);
There is no way for the server process to indicate which requests it can
accept. It must accept all requests or none. Your server process can keep
track of which process a connection request is from by examining the
address returned by accept. Once you have this address, you can use
gethostbyaddr to get the hostname. You can close down the connection
if you do not want the server process to communicate with that
particular client host or port.
When to Accept a Connection
The server process should accept a connection after executing the
listen call. Refer to the accept(2) man page for more information on
accept.
Chapter 2
Using Internet Stream Sockets
Writing the Server Process
INPUT Value
socket descriptor of
server socket
pointer to address
structure where
address will be put
pointer to the size
of struct
sockaddr_in
OUTPUT
Value
unchanged
pointer to
socket
address of
client socket
that server's
new socket is
connected to
pointer to the
actual length
of address
returned in
addr
39

Advertisement

Table of Contents
loading

Table of Contents