unixserver.py 415 Bytes
Newer Older
1 2
# Echo server demo using Unix sockets (handles one connection only)
# Piet van Oostrum
3

4
import os
5
from socket import *
6 7

FILE = 'unix-socket'
8 9
s = socket(AF_UNIX, SOCK_STREAM)
s.bind(FILE)
10

11
print('Sock name is: ['+s.getsockname()+']')
12 13

# Wait for a connection
14 15
s.listen(1)
conn, addr = s.accept()
16 17

while True:
18
    data = conn.recv(1024)
19 20
    if not data:
        break
21
    conn.send(data)
22

23
conn.close()
24
os.unlink(FILE)