Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dd918a9

Browse files
committed
Add simple Unix socket example by Piet van Oostrum.
1 parent 5b8b8cd commit dd918a9

3 files changed

Lines changed: 27 additions & 1 deletion

File tree

Demo/sockets/README

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ echosvr.py About the simplest TCP server possible.
55
finger.py Client for the 'finger' protocol.
66
ftp.py A very simple ftp client.
77
gopher.py A simple gopher client.
8+
radio.py Receive time broadcasts from broadcast.py.
89
telnet.py Client for the 'telnet' protocol.
910
throughput.py Client and server to measure TCP throughput.
11+
unixclient.py Unix socket example, client side
12+
unixserver.py Unix socket example, server side
1013
udpecho.py Client and server for the UDP echo protocol.
11-
radio.py Receive time broadcasts from broadcast.py.
1214

1315
The following file is only relevant on SGI machines (or other systems
1416
that support multicast):

Demo/sockets/unixclient.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Echo client demo using Unix sockets
2+
# Piet van Oostrum
3+
from socket import *
4+
FILE = 'blabla'
5+
s = socket(AF_UNIX, SOCK_STREAM)
6+
s.connect(FILE)
7+
s.send('Hello, world')
8+
data = s.recv(1024)
9+
s.close()
10+
print 'Received', `data`

Demo/sockets/unixserver.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Echo server program using Unix sockets (handles one connection only)
2+
from socket import *
3+
FILE = 'blabla'
4+
s = socket(AF_UNIX, SOCK_STREAM)
5+
s.bind(FILE)
6+
print 'Sock name is: ['+s.getsockname()+']'
7+
s.listen(1)
8+
conn, addr = s.accept()
9+
print 'Connected by', addr
10+
while 1:
11+
data = conn.recv(1024)
12+
if not data: break
13+
conn.send(data)
14+
conn.close()

0 commit comments

Comments
 (0)