Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sockets python:发送UDP消息_Sockets_Udp - Fatal编程技术网

Sockets python:发送UDP消息

Sockets python:发送UDP消息,sockets,udp,Sockets,Udp,我在发送UDP数据包时遇到以下挑战: 数据包的长度为40字节,除了一些计数器和校验和之外,所有字段都是常量 header='\xaf\x18\x25\x25' message= 'ABCDEFGHIGKLMNOPQRTSUVXYZ0123456' i=1 #do some checksum calculation and store result into the checksum variable message=header + chr(i) + data + chr(checksum

我在发送UDP数据包时遇到以下挑战: 数据包的长度为40字节,除了一些计数器和校验和之外,所有字段都是常量

header='\xaf\x18\x25\x25'
message= 'ABCDEFGHIGKLMNOPQRTSUVXYZ0123456'
i=1

#do some checksum calculation and store result into the checksum variable

message=header + chr(i) + data + chr(checksum >>8) + chr(checksum & 0xFF)
sock.sendto(message.encode('utf-8'), (DST_IP, int(DST_PORT)))
但是,查看wireshark,我可以看到消息是43个字节,其中我在第一个位置有一个0xC2,而不是实际的头1个字节,在校验和MSB&LSB之前有0XC3和0xC2(这是3个额外的字节)


有什么问题以及如何解决吗?

更改了编码解决了问题

sock.sendto(message.encode('charmap'), (DST_IP, int(DST_PORT)))