本文整理汇总了Python中packet.Packet.changeSequenceNum方法的典型用法代码示例。如果您正苦于以下问题:Python Packet.changeSequenceNum方法的具体用法?Python Packet.changeSequenceNum怎么用?Python Packet.changeSequenceNum使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类packet.Packet
的用法示例。
在下文中一共展示了Packet.changeSequenceNum方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from packet import Packet [as 别名]
# 或者: from packet.Packet import changeSequenceNum [as 别名]
def main(tout, filename):
global timeout
global hostname
global portnum
global file_contents
global total_packets
global payload_max
global len_of_chunks
timeout = int(tout)
channelInfo = open("channelInfo", 'r')
deets = channelInfo.read().split(' ')
hostname = deets[0]
portnum = int(deets[1])
clientSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
print payload_max
print filename
try:
with open(filename, 'rb') as f:
sequenceNum = 0
while True:
packet = struct.pack("L4", PacketType.DataPacket)
packet += struct.pack("L4", sequenceNum)
f.seek(sequenceNum * payload_max)
chunk = f.read(payload_max)
if chunk:
length_of_chunk = sys.getsizeof(chunk)
packet += struct.pack("L4", length_of_chunk+12)
print length_of_chunk
packet += struct.pack("s"+str(length_of_chunk), chunk)
file_contents.append(packet)
chunk_packet = Packet()
chunk_packet.changeSequenceNum(sequenceNum)
chunk_packet.overridePacketLength(length_of_chunk)
len_of_chunks.append(chunk_packet)
sequenceNum = sequenceNum + 1
else:
break
except:
print "Failed to open file to transmit"
sys.exit(0)
total_packets = len(file_contents)
sendFiles(clientSocket)