The UNIX Domain only allows communication between processes
executing on the same machine. In contrast to pipes, it does not
require the communicating processes to have common ancestry. For
more information on the UNIX Domain protocol, refer to the unix(7p)
man page.
UNIX domain (AF_UNIX) datagram sockets provide bidirectional,
reliable, unduplicated flow of data while preserving record boundaries.
Domain sockets significantly improve performance when compared to
local IP loopback, due primarily to the lower code execution overhead
and the fact that data is looped back at the protocol layer rather
than at the driver layer.
AF_UNIX datagram sockets allow you to send and receive messages
without establishing a connection. Each message
includes a destination address. Processes involved in data transfer
are not required to have a client-server relationship; the processes
can be symmetrical.
AF_UNIX datagram sockets allow you to send to many destinations
from one socket, and receive from many sources with one socket.
There is no two-process model, although a two-process model is the
simplest case of a more general multi-process model. The terms server
and client are used in this section only
in the application sense. For example, you might have a server process
that receives requests from several clients on the same machine.
This server process can send replies back to the various clients.
This can all be done with one AF_UNIX datagram socket for the server.
The simplest two-process model is used in this section to
describe AF_UNIX datagram sockets.
The following table lists the steps required to exchange data
between AF_UNIX datagram sockets.
Table 7-1 Exchanging
Data Between UNIX Domain Datagram Sockets
Client Process Activity | System Call Used | Server Process Activity | System
Call Used |
---|
create a socket | socket() | create a socket | socket() |
bind a socket | bind() | bind a socket | bind() |
send message | sendto()
or sendmsg() | | |
| | receive message | recvfrom() or
recvmsg() |
| | send message | sendto()
or sendmsg() |
receive
message | recvfrom()
or recvmsg() | | |
Each of these steps or activities is described in more detail
in the following sections. The description of each activity specifies
a system and includes:
What happens when
the system call is used.
Where to find details on the system call.
The domain datagram sockets programming examples are at the
end of these descriptive sections. You can refer to the example
code as you work through the descriptions.