import SocketServer

HOST = 
PORT = 12321




class EchoServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
    
    pass

class EchoRequestHandler(SocketServer.StreamRequestHandler):
    
    def handle(self):
        print % self.client_address[0]
        while True:
            line = self.rfile.readline()
            if not line: break
            print % (self.client_address[0], line.rstrip())
            self.wfile.write(line)
        print % self.client_address[0]



server = EchoServer((HOST, PORT), EchoRequestHandler)



print % server.server_address
server.serve_forever()