Plan 9 from Bell Labs’s /usr/web/sources/contrib/jas/root/sys/src/cmd/cpython/Demo/sockets/unixserver.py

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


# Echo server demo using Unix sockets (handles one connection only)
# Piet van Oostrum

import os
from socket import *

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

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

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

while True:
    data = conn.recv(1024)
    if not data:
        break
    conn.send(data)

conn.close()
os.unlink(FILE)

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.