1 import SocketServer 2 3 class MyTCPHandler(SocketServer.BaseRequestHandler): 4 def handle(self): 5 while True: 6 self.data = self.request.recv(1024).strip() 7 print '{} wrote:'.format(self.client_address[0]) 8 print self.data 9 self.request.sendall(self.data.upper())10 11 if __name__ == '__main__' :12 HOST, PORT = 'localhost', 999913 server = SocketServer.ThreadingTCPServer((HOST, PORT), MyTCPHandler)14 server.serve_forever()