#!/usr/bin/env python #-*- coding:utf-8 -*- import SocketServer class MySocker(SocketServer.BaseRequestHandler): def handle(self): print self.request,self.client_address,self.server conn = self.request conn.send('hello world!') while True: data = conn.recv(1024) if data == 'exit': break conn.send('hahah') ip_addr = ('127.0.0.1',10000) server = SocketServer.ThreadingTCPServer(ip_addr,MySocker) server.serve_forever() ############################################################ client #!/usr/bin/env python #-*- coding:utf-8 -*- import socket client = socket.socket() ip_port = ('127.0.0.1',10000) client.connect(ip_port) while True: data = client.recv(1024) print data name = raw_input('please data: ') client.send('name') if name == 'exit': break