# server
import socket
import json
sk = socket.socket()
sk.bind(('127.0.0.1',9001))
sk.listen()
conn,addr = sk.accept()
json_dic = conn.recv(1024).decode('utf-8')
dic = json.loads(json_dic)
file_path = 'F:'+'\\' + dic['file_name']
with open(file_path,'wb') as f:
while dic['file_size'] > 0:
file_conet = conn.recv(1024)
dic['file_size'] -= len(file_conet)
f.write(file_conet)
conn.close()
sk.close()
# Client Import socket Import os Import json SK = socket.socket () sk.connect (( ' 127.0.0.1 ' , 9001 )) File = r ' F: Video \ 155_ based WAF \ Nginx core knowledge say 100 \ OpenResty of firewall .mp4 ' FILE_SIZE = os.path.getsize (File) file_name = os.path.basename (File) DIC = { ' file_name ' : file_name, ' FILE_SIZE ' : FILE_SIZE} json_dic = json.dumps (DIC) sk.send (json_dic.encode ( 'utf-8')) with open(file,'rb') as f: conntent = f.read() sk.send(conntent) sk.close()