python的socket发送C结构体

xiaoxiao2026-06-12  8

公司因为测试需要,通过UDP发送C的一个结构体做测试。 这里用到的struct这个模块 结构体是这样的 typedef struct _vustr{     DWORD dwStrHeader;     DWORD dwDataLen;     DWORD dwDevID;     DWORD dwChnHLSD;     int   nVUValue; }VUSTR; udp发送代码 #coding:gb2312 import socket import os import struct dwStrHeader=33803 dwDataLen=12 dwDevID=452984837 dwChnHLSD=1 nVUValue=-80 s=socket.socket(socket.AF_INET,socket.SOCK_DGRAM) data=struct.pack('IIIIi',dwStrHeader,dwDataLen,dwDevID,dwChnHLSD,nVUValue) s.sendto(data,('192.168.0.199',33333)) s.close() 打包:struct.pack('格式化的字符串',变量1,变量2.....) 解包:struct.upack(data) DWORD 是一个unsigned int字段。所以是 I

FormatC TypePythonNotes x pad byteno value c char string of length 1 b signed char integer B unsigned char integer ? _Bool bool(1) h short integer H unsigned short integer i int integer I unsigned int integer or long l long integer L unsigned long long q long long long(2) Q unsigned long long long(2) f float float d double float s char[] string p char[] string P void * long 相关资源:python网络嗅探器仅使用socket,struct模块(从获取数据到截取TCP,UDP报文体)可扩展
转载请注明原文地址: https://www.6miu.com/read-5050010.html

最新回复(0)