UNIX domain sockets problem

Jeremy Hylton jeremy at digicool.com
Mon Apr 9 17:40:07 EDT 2001


>>>>> "SH" == Steve Holden <sholden at holdenweb.com> writes:

  SH> "bowman" <bowman at montana.com> wrote in message
  SH> news:IFiA6.187$k13.2089 at newsfeed.slurp.net...
  >>
  >> "Steven D. Arnold" <stevena at permanent.cc> wrote in message
  >> news:mailman.986695451.17699.python-list at python.org...
  >> > SERVER = socket(AF_UNIX, SOCK_DGRAM, 0)
  >> > unlink("/home/stevena/socket")
  >> > SERVER.bind("/home/stevena/socket")
  >>
  >> this snippet if from the Python Library Reference in the 2.0
  >> distro.
  >> Haven't a clue why you are trying to bind a file, but that's not
  >> the way it works.
  >>
  SH> Bzzzt. That *is* the way it works when you use sockets from the
  SH> UNIX address family (which is specified by the AF_UNIX
  SH> argument). These are UNIX named pipes, which create a point in
  SH> the UNIX filesystem which independent processes can read and
  SH> write without having to set up a direct pipeline between them.

Bzzzt!  The original poster is trying to create a Unix domain socket,
which is not a named pipe (nor a FIFO, another name for named pipe).
In Python, a named pipe would work just like a file after it's been
created with mknod.

The problem the original poster had was that the listen() call was
failing on his server.  The problem is that he specified SOCK_DGRAM.
The datagram protocol is connectionless, so there's no need to
listen() or accept().

Once the server has executed the bind() call, it can just call recv().
On the client side, the client does a connect() and then a send().

If you want to use listen() and accept(), then you need to use
SOCK_STREAM instead of SOCK_DGRAM when you create the socket.

Jeremy





More information about the Python-list mailing list