本文整理汇总了Python中packet.Packet.fromRawString方法的典型用法代码示例。如果您正苦于以下问题:Python Packet.fromRawString方法的具体用法?Python Packet.fromRawString怎么用?Python Packet.fromRawString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类packet.Packet
的用法示例。
在下文中一共展示了Packet.fromRawString方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: listenForConnections
# 需要导入模块: from packet import Packet [as 别名]
# 或者: from packet.Packet import fromRawString [as 别名]
def listenForConnections(srcIP, srcPort):
sock = Connection.createSocket()
sock.bind((srcIP, srcPort))
data, address = sock.recvfrom(Packet.MAX_PACKET_LENGTH)
conn = Connection(srcIP, srcPort, address[0], address[1], sock)
conn.buffer.append(Packet.fromRawString(data))
return conn
示例2: receive
# 需要导入模块: from packet import Packet [as 别名]
# 或者: from packet.Packet import fromRawString [as 别名]
def receive(self):
if len(self.buffer) > 0:
return self.buffer.pop()
targetTime = time.time() + (Connection.TIMEOUT * 2)
while targetTime > time.time():
data, address = self.sock.recvfrom(Packet.MAX_PACKET_LENGTH)
otherConnection = next((x for x in Connection.ActiveConnections if x.destAddress == address and x.destAddress != self.destAddress), None)
if address == self.destAddress:
if not Packet.checkIntegrity(data):
return None
return Packet.fromRawString(data)
elif otherConnection != None:
otherConnection.buffer.append(Packet.fromRawString(data))
else:
#if address is not in active connections. Throw packet away
continue
return None
示例3: test_serialize_data
# 需要导入模块: from packet import Packet [as 别名]
# 或者: from packet.Packet import fromRawString [as 别名]
def test_serialize_data(self):
self.assertEqual(
Packet.fromRawString(TestPacket.packet.serialize()).data,
TestPacket.data,
"Data Flag does not serialize or is not read Correctly"
)
示例4: test_sanityCheck
# 需要导入模块: from packet import Packet [as 别名]
# 或者: from packet.Packet import fromRawString [as 别名]
def test_sanityCheck(self):
original = TestPacket.packet
deserialized = Packet.fromRawString(original.serialize())
self.assertEqual(original, deserialized)