UNIX domain sockets problem

Steve Holden sholden at holdenweb.com
Mon Apr 9 10:04:25 EDT 2001


"bowman" <bowman at montana.com> wrote in message
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.
>
Bzzzt. That *is* the way it works when you use sockets from the UNIX address
family (which is specified by the AF_UNIX argument). These are UNIX named
pipes, which create a point in the UNIX filesystem which independent
processes can read and write without having to set up a direct pipeline
between them.

See the documentation for mknod -p, IIRC.

> # Echo server program
> import socket
>
> HOST = ''                 # Symbolic name meaning the local host
> PORT = 50007              # Arbitrary non-privileged port
> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> s.bind((HOST, PORT))
> s.listen(1)
> conn, addr = s.accept()
> print 'Connected by', addr
> while 1:
>     data = conn.recv(1024)
>     if not data: break
>     conn.send(data)
> conn.close()
>
This code is a network socket server, which unfortunately will not do what
the original author appeared to want.

regards
 Steve






More information about the Python-list mailing list