python发送字节数据

Posted 浓转淡

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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) 

保存备忘~

以上是关于python发送字节数据的主要内容,如果未能解决你的问题,请参考以下文章

将数据从套接字从C ++服务器发送到Python客户端时出现问题

Python hyper HTTP20Connection 以 1024 字节块发送数据

将数据从活动发送到片段android工作室[重复]

如何将字符串数据从活动发送到片段?

Python错误:打印(数据+“\ n”)类型错误:尝试通过网络套接字发送命令时无法将str连接到字节[重复]

Python struct作为网络数据包(未知字节序列)