Python多线程socket服务器端
2018-07-20 来源:open-open
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()
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
最新资讯
热门推荐