Bidirectional communication over unix socket (named pipe)

Donn Cave donn at u.washington.edu
Wed Mar 8 17:06:21 EST 2006


In article <1141843099.204588.200970 at i40g2000cwc.googlegroups.com>,
 "J Rice" <rice.jeffrey at gmail.com> wrote:

> Hi Donn,
> Not sure I fully understand your suggestion.  bind() only works once --
> I can't bind again in the client.  Same thing with connect() -- once I
> issue a connect in the server, it rejects it in the client.
> 
> Doing this as a stream works for what I want, but I would like to
> understand why it didn't work with datagram.

Right, bind should be on one end only, as it creates
the actual socket file.

Connect works on either end, with SOCK_DGRAM.  From
man 2 connect:

     The parameter s is a socket.  If it is of type SOCK_DGRAM,
     this call specifies the peer with which the socket is to be
     associated; this address is that to which datagrams are to
     be sent, and the only address from which datagrams are to be
     received.  If the socket is of type SOCK_STREAM, this call
     attempts to make a connection to another socket.

However, even if we're straight on this, I confess I
have only addressed your question about the unconnected
endpoint.

The other part of the problem remains, as I don't know
how to get data to actually go both ways.  I was a little
surprised by this, and have not been able to scare up any
explicit documentation, but the only example program I
could find for two-way UNIX domain datagram IPC, uses two
sockets, not one -
http://docs.hp.com/en/B2355-90136/ch07s06.html

   Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list