I found a couple of answers, but they seem to be specifically relating to Windows machines. So my question is what are the differences between pipes and sockets, and when/how should you choose one over the other?
Differences Between Pipes and Sockets It really depends on the situation and the problem which one is more suitable to use. However, we can underline some of the differences between them: While communication in pipes is uni-directional, in sockets communication, it is bidirectional.
The UNIX socket transmitted at a speed of 41,334 Mbits/s, while the anonymous pipe transmitted at a speed of 9,039 Mbits/s. So, UNIX sockets are approximately 350% faster than anonymous pipes when using a 1 Mbyte block size.
Socket weld pipe fittings are used to permanently join pipes that are inserted into a recess in the fitting, flange or valve. Once correctly inserted, fillet type sealing welds are applied to join the pipe to the fitting.
what are the differences between pipes and sockets, and when/how should you choose one over the other?
Both pipes and sockets handle byte streams, but they do it in different ways...
Usage:
read()
and write()
to a pipe.BTW, you can use netcat or socat to join a socket to a pipe.
To complete the answer given by Mike, it is important to mention the existence of UNIX domain sockets, which are available on any POSIX compliant operating system. Although very similar to "normal" internet sockets in terms of usage semantics, they are purely local to the machine (of course internet sockets can also work locally), and thus almost behave like a pipe. Almost, because a UNIX pipe is by definition unidirectional:
Pipes and FIFOs (also known as named pipes) provide a unidirectional interprocess communication channel. A pipe has a read end and a write end. Data written to the write end of a pipe can be read from the read end of the pipe. (excerpt from the man page pipe(7))
UNIX domain sockets also have a very unusual feature, as besides data, they also allow sending file descriptors: this way, an unprivileged process can access any file whose descriptor has been sent over the socket. This technique, according to Wikipedia, is used by the ClamAV antivirus scanning daemon.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With