summaryrefslogtreecommitdiffstats
path: root/Demo/sockets/unixserver.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1998-01-28 16:54:00 (GMT)
committerGuido van Rossum <guido@python.org>1998-01-28 16:54:00 (GMT)
commitdd918a990a274c808081d35beb1fd222385c86b3 (patch)
tree7297644eee4432f9d8477426256418e772406737 /Demo/sockets/unixserver.py
parent5b8b8cd6c08d8efb62d26ee6ec878a792a71d16f (diff)
downloadcpython-dd918a990a274c808081d35beb1fd222385c86b3.zip
cpython-dd918a990a274c808081d35beb1fd222385c86b3.tar.gz
cpython-dd918a990a274c808081d35beb1fd222385c86b3.tar.bz2
Add simple Unix socket example by Piet van Oostrum.
Diffstat (limited to 'Demo/sockets/unixserver.py')
-rw-r--r--Demo/sockets/unixserver.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/Demo/sockets/unixserver.py b/Demo/sockets/unixserver.py
new file mode 100644
index 0000000..3d6f3c3
--- /dev/null
+++ b/Demo/sockets/unixserver.py
@@ -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()