Bidirectional communication over unix socket (named pipe)

Raúl Gómez C. nachogomez at gmail.com
Thu Oct 18 00:59:46 EDT 2007


This is the code I'm running (just the server):

#!/usr/bin/python
import socket
import os, os.path
import time

if os.path.exists("hpcd_sock"):
    os.remove("hpcd_sock")

server = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
server.bind("hpcd_sock")

while True:
    datagram = server.recv(1024)
    if not datagram:
        break
    print datagram
    # the preceding works, and I see the TEST TEST TEST statement the client
sent

    time.sleep(2)
    # it dies on the next statement.
    server.send("Thank you\n")

server.close()
if os.path.exists("hpcd_sock"):
    os.remove("hpcd_sock")


And this is the error that its giving me:

Traceback (most recent call last):
  File "server_socket.py", line 13, in <module>
    datagram = server.recv(1024)
socket.error: (22, 'Invalid argument')
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20071018/ef908875/attachment.html>


More information about the Python-list mailing list