forked from python/cpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add simple Unix socket example by Piet van Oostrum.
- Loading branch information
1 parent
5b8b8cd
commit dd918a9
Showing
3 changed files
with
27 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |