mirror of
https://github.com/python/cpython.git
synced 2025-07-23 11:15:24 +00:00
Add simple Unix socket example by Piet van Oostrum.
This commit is contained in:
parent
5b8b8cd6c0
commit
dd918a990a
3 changed files with 27 additions and 1 deletions
14
Demo/sockets/unixserver.py
Normal file
14
Demo/sockets/unixserver.py
Normal file
|
@ -0,0 +1,14 @@
|
|||
# Echo server program using Unix sockets (handles one connection only)
|
||||
from socket import *
|
||||
FILE = 'blabla'
|
||||
s = socket(AF_UNIX, SOCK_STREAM)
|
||||
s.bind(FILE)
|
||||
print 'Sock name is: ['+s.getsockname()+']'
|
||||
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()
|
Loading…
Add table
Add a link
Reference in a new issue