BSD Sockets Interface Programmer's Guide

128 Chapter 6
Using UNIX Domain Stream Sockets
Writing the Server Process
Writing the Server Process
This section explains the calls your server process must make to connect
with and serve a client process.
Creating a Socket
The server process must call socket to create a communication
endpoint. 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), –1 if failure
occurs.
Example: s = socket (AF_UNIX, SOCK_STREAM, 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 after a BSD Sockets
connection is established. A socket descriptor is treated like a file
descriptor for an open file.
When to Create Sockets
The server 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_STREAM
protocol underlying protocol to be used 0 (default)