BSD Sockets Interface Programmer's Guide

152 Chapter 7
Using UNIX Domain Datagram Sockets
Writing the Server and Client Processes
Writing the Server and Client Processes
This section discusses 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: #include <sys/types.h>
#include <sys/socket.h>
System call: s = socket(af, type, protocol)
int af, type, protocol;
Function result: socket number (HP-UX file descriptor) if successful, -1
if socket call fails.
Example: #include <sys/type.h>
#include <sys/socket.h>
...
s = socket(AF_UNIX, SOCK_DGRAM, 0)
When to Create Sockets
The server or client process should create sockets before any other BSD
Sockets system calls. Refer to the socket(2) man page for more
information on socket.
Parameter Description of Contents INPUT Value
af address family AF_UNIX
type socket type SOCK_DGRAM
protocol underlying protocol to be
used
0 (default)