1. 程式人生 > >python發送字節數據

python發送字節數據

socket 1.10 python pri color ket nec net import

 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)

保存備忘~

python發送字節數據