###### SERVER CODE ####### from socket import * # Create an unbond and not-connected socket. sock = socket(AF_UNIX, SOCK_STREAM) # Bind the socket to "MyBindName" in the abstract namespace. Note the null-byte. sock.bind("\0MyBindName") # Create a backlog queue for up to 1 connection. sock.listen(1) # Blocks until a connection arrives. A tuple (connected_socket, None) is returned # upon connection. Note we get the first argument and throw away the rest. conn = sock.accept()[0] # Say hi conn.send("Hello World\n") # Wait for response msg = conn.recv(100) print msg # Close it, this will unblock the other peer in case it's waiting for another message. conn.close() ####### CLIENT CODE ####### from socket import * # Create an unbond and not-connected socket. sock = socket(AF_UNIX, SOCK_STREAM) # Connect to the peer registered as "MyBindName" in the abstract namespace. Note the '\0'. sock.connect("\0MyBindName") # Wait for message msg = sock.recv(100) print msg # Send reply sock.send("Hi there!\n") # Block until new message arrives msg = sock.recv(100) # When the socket is closed cleanly, recv unblocks and returns "" if not msg: print "It seems the other side has closed its connection" # Close it sock.close()