当前位置: 首页>>代码示例>>Python>>正文


Python Packet.unwrap方法代码示例

本文整理汇总了Python中packet.Packet.unwrap方法的典型用法代码示例。如果您正苦于以下问题:Python Packet.unwrap方法的具体用法?Python Packet.unwrap怎么用?Python Packet.unwrap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在packet.Packet的用法示例。


在下文中一共展示了Packet.unwrap方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: receivePacket

# 需要导入模块: from packet import Packet [as 别名]
# 或者: from packet.Packet import unwrap [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
开发者ID:VictorJuliani,项目名称:Redes,代码行数:45,代码来源:reliable_sock.py


注:本文中的packet.Packet.unwrap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。