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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/409.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
在Python中通过UDP发送数据包_Python_Sockets_Python 2.7_Networking - Fatal编程技术网

在Python中通过UDP发送数据包

在Python中通过UDP发送数据包,python,sockets,python-2.7,networking,Python,Sockets,Python 2.7,Networking,我希望我的UDP数据包能有这些信息,例如: data = "83053163021478010102010370020000000000" 我正在使用以下代码发送它,该代码运行良好(我可以看到它在wireshark上运行): 当我在wireshark中查看数据包时,我想要(wireshark)数据包==数据。如何声明/转换数据类型以实现这一点。我认为这应该可以做到: import codecs data = codecs.decode("8305316302147801010201037002

我希望我的UDP数据包能有这些信息,例如:

data = "83053163021478010102010370020000000000"
我正在使用以下代码发送它,该代码运行良好(我可以看到它在wireshark上运行):


当我在wireshark中查看数据包时,我想要(wireshark)数据包==数据。如何声明/转换数据类型以实现这一点。

我认为这应该可以做到:

import codecs
data = codecs.decode("83053163021478010102010370020000000000", "hex_codec")
然后您可以发送与现在相同的
数据


ref:

您的意思是要将数据中的十六进制值转换为原始二进制?否则我不理解questiondata是一个十六进制字符串,表示为ascii字符串。我希望listener.sendto(data,(IP,PORT))以数据字符串等于hcs的文本十六进制字节的形式发送数据,非常感谢,这工作非常完美,正是我想要做的。你不知道我对你的回答有多感激!
import codecs
data = codecs.decode("83053163021478010102010370020000000000", "hex_codec")