import threading import SocketServer import json import time class ThreadedTCPRequestHandler(SocketServer.BaseRequestHandler): def handle(self): start_time=time.time() print start_time data = self.request.recv(1024) jdata = json.loads(data) try: print jdata#写自己的处理过程 except Exception as e: msg=e.message else: msg='success' # host=self.client_address # sub_thread = threading.current_thread() response = {'data':data,'message':msg} print response jresp = json.dumps(response) self.request.sendall(jresp) print 'count_time---',time.time()-start_time if __name__ == "__main__": server=SocketServer.ThreadingTCPServer(('192.168.15.32',5000),ThreadedTCPRequestHandler) # ip, port = server.server_address print " .... waiting for connection" server.serve_forever()
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/8137.html