On Thu, May 17, 2007 at 08:50:28PM +0200, Arnold Krille wrote:
Am Donnerstag, 17. Mai 2007 schrieb Malte Steiner:
I wonder what is the best way to connect
applications on the same
computer. Usually I use network and localhost plus custom protocols or
OSC to let them communicate but wonder if pipes are more efficient. The
data to be exchanged is usually control rate, not audio nor video streams.
So what are the pros and cons of pipes versus network?
While pipes are faster (which is not interesting for control data only)
osc+network makes it extendable. Maybe in the future one part of your app
will run on a different host. If you started with pipes you have to program a
whole new communication. With osc and network you just allow other addresses
than localhost...
If efficiency or latency matters, have a look at unix domain sockets.
The API is the same like of the (inet) network stuff, but their efficiency is
close (if not identical) to pipes. So it's 'pipes AND network' ;-)
Just use the same protocol on top of both, the differences mainly
concern the socket() parameters and the initialisation of the sockaddr
for bind() and connect(). As long as you don't rely on things like
SEQPACKET, credentials, passing of file descriptors (all n/a with ip)
and out-of-band/urgent data (not available with unix domain sockets),
the socket type is transparent to the higher layers.
BTW, that's what the X11 protocol is using: if you set DISPLAY=:0 it
uses the named unix socket /tmp/.X11-unix/X0, if you set
DISPLAY=localhost:0 it does TCP/IP through the 'lo' network device
(requires that the server is not started with '-nolisten tcp', just in
case you want to test this)
see unix(7) or your copy of Steven's 'UNIX network programming'
HTH,
Jacob