Writing The Server And Client Processes; Creating Sockets - 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 Datagram Sockets

Writing the Server and Client Processes

Writing the Server and Client Processes
This section explains the calls your server and client processes must
make.

Creating Sockets

Both processes must call socket to create communication endpoints.
socket and its parameters are described in the following table.
Include files:
System call:
Function result: socket number (HP-UX file descriptor), –1 if failure
Example:
ls = socket (AF_INET, SOCK_DGRAM, 0);
The socket number returned is the socket descriptor for the newly
created socket. This number is an HP-UX file descriptor and can be used
for reading, writing or any standard file system calls. A socket descriptor
is treated like a file descriptor for an open file.
To use write(2) with a datagram socket, you must declare a default
NOTE
address. Refer to the "Specifying a Default Socket Address" section of the
"Advanced Topics for Internet Datagram Sockets" chapter for more
information.
92
#include <sys/types.h>
#include <sys/socket.h>
s = socket(af, type, protocol)
int s, af, type, protocol;
Parameter
Description of Contents
af
address family
type
socket type
protocol
underlying protocol to be
used
occurs.
INPUT Value
AF_INET
SOCK_DGRAM
0 (default) or value
returned by
getprotobyname
Chapter 4

Advertisement

Table of Contents
loading

Table of Contents