File: class/Workbook/Examples/Lecture14/echoserver.py

from socket import *      # get constructor and constants
HOST = ''                 # symbolic name of the local host
PORT = 50007              # arbitrary non-privileged server
s = socket(AF_INET, SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(1)
conn, addr = s.accept()
print 'Connected by', addr
while 1:
    data = conn.recv(1024)   # use connected socket
    if not data: break       # repeat accept for > 1 client
    conn.send(data)
conn.close()



[Home page] Books Code Blog Python Author Train Find ©M.Lutz