if __name__ == "__main__": # Port 0 means to select an arbitrary unused port HOST, PORT = "localhost", 50001 SocketServer.TCPServer.allow_reuse_address = True server = ThreadedTCPServer((HOST, PORT), ThreadedTCPRequestHandler) ip, port = server.server_address
# Start a thread with the server -- that thread will then start one # more thread for each request server_thread = threading.Thread(target=server.serve_forever)
? # Exit the server thread when the main thread terminates server_thread.daemon = True server_thread.start() print "Server loop running in thread:", server_thread.name print " .... waiting for connection"
# Activate the server; this will keep running until you # interrupt the program with Ctrl-C server.serve_forever()