本文整理汇总了Python中packet.Packet.sniff方法的典型用法代码示例。如果您正苦于以下问题:Python Packet.sniff方法的具体用法?Python Packet.sniff怎么用?Python Packet.sniff使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类packet.Packet
的用法示例。
在下文中一共展示了Packet.sniff方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: receive
# 需要导入模块: from packet import Packet [as 别名]
# 或者: from packet.Packet import sniff [as 别名]
def receive(self):
self.buff = ''
self.msg_buff = ''
while True:
data = self.s.recv(MAX_RECV_SIZE)
if not data:
time.sleep(0.01)
continue
self.buff += data
while True:
packet = Packet.sniff(self.buff)
if packet is None:
break
# Slice buffer
self.buff = self.buff[packet.size():]
# Append text data
self.msg_buff += packet.body
while True:
message = Message.sniff(self.msg_buff)
if message is None:
break
# Slice message buffer
self.msg_buff = self.msg_buff[(message.size() + 1):] # +1 means to skip '\0' in the end
yield message