summaryrefslogtreecommitdiffstats
path: root/Demo/sockets
diff options
context:
space:
mode:
Diffstat (limited to 'Demo/sockets')
-rw-r--r--Demo/sockets/README1
-rw-r--r--Demo/sockets/unixclient.py4
-rw-r--r--Demo/sockets/unixserver.py15
3 files changed, 14 insertions, 6 deletions
diff --git a/Demo/sockets/README b/Demo/sockets/README
index 21ed808..f5405ab 100644
--- a/Demo/sockets/README
+++ b/Demo/sockets/README
@@ -19,4 +19,3 @@ mcast.py A Python translation of
/usr/people/4Dgifts/examples/network/mcast.c
(Note that IN.py is in ../../lib/sgi.)
-See also ../../lib/nntp.py for another example of socket code.
diff --git a/Demo/sockets/unixclient.py b/Demo/sockets/unixclient.py
index cccd617..fdbcc7a 100644
--- a/Demo/sockets/unixclient.py
+++ b/Demo/sockets/unixclient.py
@@ -1,7 +1,9 @@
# Echo client demo using Unix sockets
# Piet van Oostrum
+
from socket import *
-FILE = 'blabla'
+
+FILE = 'unix-socket'
s = socket(AF_UNIX, SOCK_STREAM)
s.connect(FILE)
s.send('Hello, world')
diff --git a/Demo/sockets/unixserver.py b/Demo/sockets/unixserver.py
index 5eccabb..b73f857 100644
--- a/Demo/sockets/unixserver.py
+++ b/Demo/sockets/unixserver.py
@@ -1,17 +1,24 @@
# Echo server demo using Unix sockets (handles one connection only)
# Piet van Oostrum
+
import os
from socket import *
-FILE = 'blabla'
+
+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()
-print 'Connected by', addr
-while 1:
+
+while True:
data = conn.recv(1024)
- if not data: break
+ if not data:
+ break
conn.send(data)
+
conn.close()
os.unlink(FILE)