本文整理汇总了Python中packet.Packet.validChecksum方法的典型用法代码示例。如果您正苦于以下问题:Python Packet.validChecksum方法的具体用法?Python Packet.validChecksum怎么用?Python Packet.validChecksum使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类packet.Packet
的用法示例。
在下文中一共展示了Packet.validChecksum方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: receivePacket
# 需要导入模块: from packet import Packet [as 别名]
# 或者: from packet.Packet import validChecksum [as 别名]
def receivePacket(self, data):
packet = Packet(data)
packet.unwrap()
self.attempts = 0
if not packet.validChecksum() or random.randint(1, 100) < self.pcorr: # do not receive broken packets or simulate a broken packet
print "Bad checksum received on seg: " + str(packet.seg) + " ack: " + str(packet.ack)
return None
if packet.con > 0:
self.seg = packet.con # set seg with nextSeg received in con field
self.ack = packet.con
self.init = True
if not self.requesting: # this socket received the connection request, then ack it
print "Connection request from " + str(self.addr)
self.buff.put(Packet('', end = packet.end, con = self.nextSeg)) # ack with nextSeg expected on con field
return packet
else:
print "Connection established!"
elif (packet.ack > 0): # ack packet
self.lock.acquire(True)
if packet.ack == self.ack: # expected ack!
self.ack += 1
self.playTimer() # ack received, start timer again
print "Received expected ack " + str(packet.ack) + " on connection " + str(self.addr)
if packet.end: # ack for end packet received
self.endCon()
self.lock.release()
elif packet.seg < self.nextSeg:
self.ackPacket(packet.seg, packet.end) # old packet received again, ACK might be lost.. send it again
print "Duplicated packet " + str(packet.seg) + ". Sending ack again and ignoring"
elif self.nextSeg == packet.seg: # expected seg!
self.nextSeg += 1
self.ackPacket(packet.seg, packet.end)
print "Acking packet " + str(packet.seg)
return packet
#else:
# print "Bad packet received! Seg: " + str(packet.seg) + " expected: " + str(self.nextSeg) + " ack: " + str(packet.ack)
return None