~malept/ubuntu/lucid/python2.6/dev-dependency-fix

« back to all changes in this revision

Viewing changes to Demo/sockets/unixserver.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2009-02-13 12:51:00 UTC
  • Revision ID: james.westby@ubuntu.com-20090213125100-uufgcb9yeqzujpqw
Tags: upstream-2.6.1
ImportĀ upstreamĀ versionĀ 2.6.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Echo server demo using Unix sockets (handles one connection only)
 
2
# Piet van Oostrum
 
3
 
 
4
import os
 
5
from socket import *
 
6
 
 
7
FILE = 'unix-socket'
 
8
s = socket(AF_UNIX, SOCK_STREAM)
 
9
s.bind(FILE)
 
10
 
 
11
print 'Sock name is: ['+s.getsockname()+']'
 
12
 
 
13
# Wait for a connection
 
14
s.listen(1)
 
15
conn, addr = s.accept()
 
16
 
 
17
while True:
 
18
    data = conn.recv(1024)
 
19
    if not data:
 
20
        break
 
21
    conn.send(data)
 
22
 
 
23
conn.close()
 
24
os.unlink(FILE)