python发送字节数据

 1 # Control Program
 2 #
 3 #
 4 
 5 
 6 #  socket  :
 7 import socket
 8 import struct  
 9 #  socket:
10 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
11 #  :
12 s.connect(('192.168.1.10', 6000))
13 
14 cmd = "AA555453010000CCFF" 
15 str1 = "" 
16 str2 = ""  
17 while cmd:  
18     str1 = cmd[0:2]  
19     s_t = int( str1, 16)
20     str2 += struct.pack('B', s_t) 
21     cmd = cmd[2:] 
22 
23 print repr(str2)              
24 s.send(str2) 

保存备忘~

转载于:https://www.cnblogs.com/boyen/p/9017826.html

你可能感兴趣的:(python发送字节数据)