使用socket中的struck来实现客户端发送
服务端:
# -*- coding: UTF-8 -*- import socket, time, socketserver, struct, os, _thread host = '127.0.0.1' port = 12307 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # 定义socket类型 s.bind((host, port)) # 绑定需要监听的Ip和端口号,tuple格式 s.listen(1) def conn_thread(connection, address): while True: try: connection.settimeout(600) fileinfo_size = struct.calcsize('12sl')#12s表示12个字符,l表示一个长整型数 buf = connection.recv(fileinfo_size) if buf: # 如果不加这个if,第一个文件传输完成后会自动走到下一句,需要拿到文件大小信息才可以继续执行 filename, filesize = struct.unpack('12sl', buf) filename_f = filename.decode("utf-8").strip(' 0') # C语言中’