Node:Socket Pairs, Previous:Closing a Socket, Up:Open/Close Sockets
A socket pair consists of a pair of connected (but unnamed)
sockets. It is very similar to a pipe and is used in much the same
way. Socket pairs are created with the socketpair
function,
declared in sys/socket.h
. A socket pair is much like a pipe; the
main difference is that the socket pair is bidirectional, whereas the
pipe has one input-only end and one output-only end (see Pipes and FIFOs).
int socketpair (int namespace, int style, int protocol, int filedes[2]) | Function |
This function creates a socket pair, returning the file descriptors in
filedes[0] and filedes[1] . The socket pair
is a full-duplex communications channel, so that both reading and writing
may be performed at either end.
The namespace, style and protocol arguments are
interpreted as for the If style specifies a connectionless communication style, then the two sockets you get are not connected, strictly speaking, but each of them knows the other as the default destination address, so they can send packets to each other. The
|