Python 3.x 如何在Python中从字节数组中删除和添加字节
我正在发送和接收二进制文件,需要为发送的每个数据包添加一个会话号 我尝试过将其作为一个完全不同的数据包发送,但这需要很大的开销 如何追加整数,然后在以后从字节中拆分整数 发件人的外观如下所示:Python 3.x 如何在Python中从字节数组中删除和添加字节,python-3.x,Python 3.x,我正在发送和接收二进制文件,需要为发送的每个数据包添加一个会话号 我尝试过将其作为一个完全不同的数据包发送,但这需要很大的开销 如何追加整数,然后在以后从字节中拆分整数 发件人的外观如下所示: file = open(file.pdf, rb) while PCOUNT < PTOTAL: data = file.read(1024) data = data.(I would like to add PCOUNT to beggining of data) sen
file = open(file.pdf, rb)
while PCOUNT < PTOTAL:
data = file.read(1024)
data = data.(I would like to add PCOUNT to beggining of data)
sendto(data,(host,port))
PCOUNT += 1
file.close
data = recv(data)
data = data.split(somehow) #or some other method
session_number = data[0]
binary_data = data[1]
听起来您需要停止使用原始字节,开始使用协议。低级别套接字编程UDP用于文件传输,我正在编写自己的协议