Skip to content

Commit

Permalink
Add simple Unix socket example by Piet van Oostrum.
Browse files Browse the repository at this point in the history
  • Loading branch information
gvanrossum committed Jan 28, 1998
1 parent 5b8b8cd commit dd918a9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Demo/sockets/README
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ echosvr.py About the simplest TCP server possible.
finger.py Client for the 'finger' protocol.
ftp.py A very simple ftp client.
gopher.py A simple gopher client.
radio.py Receive time broadcasts from broadcast.py.
telnet.py Client for the 'telnet' protocol.
throughput.py Client and server to measure TCP throughput.
unixclient.py Unix socket example, client side
unixserver.py Unix socket example, server side
udpecho.py Client and server for the UDP echo protocol.
radio.py Receive time broadcasts from broadcast.py.

The following file is only relevant on SGI machines (or other systems
that support multicast):
Expand Down
10 changes: 10 additions & 0 deletions Demo/sockets/unixclient.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Echo client demo using Unix sockets
# Piet van Oostrum
from socket import *
FILE = 'blabla'
s = socket(AF_UNIX, SOCK_STREAM)
s.connect(FILE)
s.send('Hello, world')
data = s.recv(1024)
s.close()
print 'Received', `data`
14 changes: 14 additions & 0 deletions Demo/sockets/unixserver.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit dd918a9

Please sign in to comment.