Ticket #837: openSocketServer.py

File openSocketServer.py, 407 bytes (added by stefanomasini, 10 years ago)
Line 
1
2# Echo server program
3import socket
4
5HOST = ''                 # Symbolic name meaning the local host
6PORT = 50007              # Arbitrary non-privileged port
7s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
8s.bind((HOST, PORT))
9s.listen(1)
10conn, addr = s.accept()
11print 'Connected by', addr
12while 1:
13    data = conn.recv(1024)
14    if not data: break
15    conn.send(data)
16conn.close()