UDP协议学习 https://blog.csdn.net/aa1928992772/article/details/85240358?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522163428541316780366546792%2522%252C%2522scm%2522%253A%252220140713.130102334…%2522%257D&request_id=163428541316780366546792&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2alltop_positive~default-1-85240358.first_rank_v2_pc_rank_v29&utm_term=udp%E5%8D%8F%E8%AE%AE&spm=1018.2226.3001.4187
python代码 import socket import binascii import struct
udpReceivedata = []
udpSenddata = [0xed ,0xfe ,0xcd ,0xff ,0x64 ,0x08 ,0xc0 ,0xa8 ,0x64 ,0x06 ,0x00 ,0x09 ,0x00 ,0x00 ,0x01 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00, 0x00 ,0x09 ,0x07 ,0xe5 ,0x0a ,0x0e ,0x13 ,0x18 ,0x18 ,0x02 ,0x48 ,0x95 ,0xbe ,0xdd ] #udpdata = [0X5a,0xa5,0X10,0x04,0X18,0x00,0X00,0x00,0X97,0xf8,0X41,0x61,0X00,0x00,0X00,0x00,0X07,0x00,0X00,0x00,0X00,0x00,0X00,0x00] str1 = “” str2 = “” num = 0 def main(): global str1,str2,udpReceivedata udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) command = bytearray(udpSenddata) udp.sendto(command, (‘192.168.100.6’, 1234)) data,networkinfo = udp.recvfrom(1024) print(data) print(networkinfo) for i in range(0,len(data)): udpReceivedata.append(int(data[i])) print(udpReceivedata) udp.close()
if name == ‘main’: main()
|