服务端
import socket,os,sys,json,struct,socketserver BASE_DIR=os.path.dirname(os.path.dirname(os.path.abspath(__file__))) SHARE_DIR=os.path.join(BASE_DIR,"share") TMP_DIR=os.path.join(BASE_DIR,"tmp") sys.path.append(BASE_DIR) from lib.md5sum import md5sum from lib.random_str import make_code class MyTcphandler(socketserver.BaseRequestHandler): def handle(self): conn = self.request print(conn) while True: #通信循环 try: data=conn.recv(1024) if not data: break params = json.loads(data.decode('utf-8')) # params=['get','a.txt'] cmd = params[0] # if hasattr(self, cmd) and len(params)>=2: func = getattr(self, cmd) func(params) else: conn.send("N".encode("utf-8")) print('