diff options
author | Guido van Rossum <guido@python.org> | 1998-01-28 16:54:00 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1998-01-28 16:54:00 (GMT) |
commit | dd918a990a274c808081d35beb1fd222385c86b3 (patch) | |
tree | 7297644eee4432f9d8477426256418e772406737 /Demo | |
parent | 5b8b8cd6c08d8efb62d26ee6ec878a792a71d16f (diff) | |
download | cpython-dd918a990a274c808081d35beb1fd222385c86b3.zip cpython-dd918a990a274c808081d35beb1fd222385c86b3.tar.gz cpython-dd918a990a274c808081d35beb1fd222385c86b3.tar.bz2 |
Add simple Unix socket example by Piet van Oostrum.
Diffstat (limited to 'Demo')
-rw-r--r-- | Demo/sockets/README | 4 | ||||
-rw-r--r-- | Demo/sockets/unixclient.py | 10 | ||||
-rw-r--r-- | Demo/sockets/unixserver.py | 14 |
3 files changed, 27 insertions, 1 deletions
diff --git a/Demo/sockets/README b/Demo/sockets/README index e844ac6..21ed808 100644 --- a/Demo/sockets/README +++ b/Demo/sockets/README @@ -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): diff --git a/Demo/sockets/unixclient.py b/Demo/sockets/unixclient.py new file mode 100644 index 0000000..a0d80f6 --- /dev/null +++ b/Demo/sockets/unixclient.py @@ -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` 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() |