服务端
import socketserver, struct, json, os
IP = '127.0.0.1'
PORT = 8080
SERVER_ADD = (IP, PORT)
class MyTCPClass(socketserver.BaseRequestHandler):
def get_upload(self, hander):
file_size = hander['file_length']
res = b''
size = 0
while size < file_size:
date = self.request.recv(1024)
size += len(date)
res += date
# print(res.decode('utf-8'))
while True:
# tar_path = input('请输入指定目录:').strip()
tar_path = hander['tar_path']
if not os.path.isdir(tar_path):
# print('目录不存在')
return False, '服务器,目标目录不存在'
f_name = hander['file_name']
f_path = os.path.join(tar_path, f_name)
with open(f_path, 'w', encoding='utf-8')as f: