下面是我通过套接字接收数据的代码。在
from twisted.internet.protocol import Factory
from twisted.protocols.basic import LineReceiver
from twisted.internet import reactor
class Chat(LineReceiver):
def lineReceived(self, line):
print(line)
class ChatFactory(Factory):
def __init__(self):
self.users = {} # maps user names to Chat instances
def buildProtocol(self, addr):
return Chat()
reactor.listenTCP(9600,ChatFactory())
reactor.run()
我得到客户的回复
^{pr2}$它是十六进制码和ascii码的结合,位置信息采用ascii格式。 将这些数据转换为人类可读格式的最佳方法是什么?
需要解析头文件。在
<$$><L><ID><command><data><checksum><\r\n>
0x24
的十六进制代码表示提前谢谢。在
这可以用二进制字符串来解决:
另一个答案是指向struct的链接
你可以使用
struct.unpack()
,但你必须知道你要解包什么(int、long、signed等),如果它编码在1个以上的字节上,ASCII是7位,编码在1个字节上。在阅读有关structhere的更多信息。在
相关问题 更多 >
编程相关推荐