8
Contents
Using Broadcast Addresses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
122
6.
Using UNIX Domain Stream Sockets
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
124
Preparing Address Variables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
126
Declaring Socket Address Variables . . . . . . . . . . . . . . . . . . . . . . . . .
126
Writing the Server Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
128
Creating a Socket . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
128
Binding a Socket Address to the Server Process's Socket . . . . . . . .
129
Setting the Server Up to Wait for Connection Requests. . . . . . . . . .
130
Accepting a Connection. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
131
Writing the Client Process. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
133
Creating a Socket . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
133
Requesting a Connection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
134
Sending and Receiving Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
136
Sending Data. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
136
Receiving Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
137
Flag Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
138
Closing a Socket . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
139
Example Using UNIX Domain Stream Sockets . . . . . . . . . . . . . . . . . .
140
7.
Using UNIX Domain Datagram Sockets
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
148
Preparing Address Variables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
150
Declaring Socket Address Variables . . . . . . . . . . . . . . . . . . . . . . . . .
150
Writing the Server and Client Processes . . . . . . . . . . . . . . . . . . . . . . .
152
Creating Sockets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
152
Binding Socket Addresses to UNIX Domain Datagram Sockets . . .
153