# Echo server program # Server listening on PORT waiting to recieve a connection # when a user connects it waits for a message and then replies # to the sender with the same message, then quits import socket HOST = '' # Symbolic name meaning the localhost (localhost = our own machine) PORT = 50007 # Arbitrary non-privileged port s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # creating a new socket s.bind((HOST, PORT)) # bind the socket to the host and port we want to listen on s.listen(1) # 1 = number of queued connections conn, addr = s.accept() # conn is the new socket object, s the addr connecting on the other end print 'Connected by', addr # print the address of the client that has just connected while 1: # wait for message data = conn.recv(1024) # 1024 = buffer size = how much data can be recieved if not data: break conn.send(data) # send response conn.close()