unix domain socket VS named pipes?
Solution 1:
UNIX-domain sockets are generally more flexible than named pipes. Some of their advantages are:
- You can use them for more than two processes communicating (eg. a server process with potentially multiple client processes connecting);
- They are bidirectional;
- They support passing kernel-verified UID / GID credentials between processes;
- They support passing file descriptors between processes;
- They support packet and sequenced packet modes.
To use many of these features, you need to use the send()
/ recv()
family of system calls rather than write()
/ read()
.
Solution 2:
One difference is that named pipes are one-way, so you'll need to use two of them in order to do two-way communication. Sockets of course are two way. It seems slightly more complicated to use two variables instead of one (that is, two pipes instead of one socket).
Also, the wikipedia article is pretty clear on the following point: "Unix domain sockets may be created as byte streams or as datagram sequences, while pipes are byte streams only."
Named pipes are, in fact, bi-directional but half-duplex. This means that communication may go either from end A to end B, or B to A, but never both at the same time.