本文整理汇总了Python中Packet.byte_to_Packet方法的典型用法代码示例。如果您正苦于以下问题:Python Packet.byte_to_Packet方法的具体用法?Python Packet.byte_to_Packet怎么用?Python Packet.byte_to_Packet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Packet
的用法示例。
在下文中一共展示了Packet.byte_to_Packet方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: write_packets
# 需要导入模块: import Packet [as 别名]
# 或者: from Packet import byte_to_Packet [as 别名]
def write_packets(expected, outfile, r_in, r_out):
r_in.setblocking(True)
rcvd_bytes, address = r_in.recvfrom(1024)
rcvd = Packet.byte_to_Packet(rcvd_bytes)
if (rcvd.magicno == 0x497E and rcvd.packet_type == 0): # only run if it works, otherwise packet dropped
acknowledgement_packet = Packet.Packet(0x497E, 1, rcvd.seqno, 0, '')
awk_buffer = acknowledgement_packet.convert_to_bytes()
r_out.sendto(awk_buffer, (ip, Port.cr_in_port))
print("twas sent right?")
print("seqno: " + str(rcvd.seqno))
if rcvd.seqno == expected:
# rcvd is the received data packet # empty data field
expected = 1 - expected
print("length: " + str(rcvd.data_len))
if rcvd.data_len > 0:
print("this is data: " + rcvd.data)
outfile.write(rcvd.data)
elif rcvd.data_len == 0:
outfile.close()
r_in.close() # unnecessary?
r_out.close()
exit()
else:
# we should test some with weird or missing magicnos, if we havent already
print("Error: invalid magicno. Must be 0x497E")
return expected;
示例2: carry_on
# 需要导入模块: import Packet [as 别名]
# 或者: from Packet import byte_to_Packet [as 别名]
def carry_on(exit_flag, inputfile, next1, num_of_packets):
rcvd_bytes, address = Socket.s_in.recvfrom(1024)
rcvd = Packet.byte_to_Packet(rcvd_bytes) # converts bytes to the recieved ack_packet
if rcvd.magicno == 0x497E and rcvd.packet_type == 1 and rcvd.data_len == 0:
if rcvd.seqno == next1:
next1 = 1 - next1
if exit_flag == True:
inputfile.close()
print("It took " + str(num_of_packets) + " packets to send the file")
exit()
# else go back to beginning of outer loop, idk if we need an else statement or it will do it itself ya feel me
return next1
示例3: carry_on
# 需要导入模块: import Packet [as 别名]
# 或者: from Packet import byte_to_Packet [as 别名]
def carry_on(exit_flag, inputfile, next1, num_of_packets, outOfLoop):
print("what")
rcvd_bytes, address = Socket.s_in.recvfrom(1024)
rcvd = Packet.byte_to_Packet(rcvd_bytes) # converts bytes to the recieved ack_packet
if rcvd.magicno == 0x497E and rcvd.packet_type == 1 and rcvd.data_len == 0:
if rcvd.seqno == next1:
next1 = 1 - next1
if exit_flag == True:
inputfile.close()
print("It took " + str(num_of_packets) + " packets to send the file")
exit()
else:
outOfLoop = True
num_of_packets += 1 # add to number of packets sent (included repeated packets)
return (outOfLoop, num_of_packets, next1)
示例4: write_packets
# 需要导入模块: import Packet [as 别名]
# 或者: from Packet import byte_to_Packet [as 别名]
def write_packets(expected, outfile, r_in, r_out):
r_in.setblocking(True)
rcvd_bytes, address = r_in.recvfrom(1024)
rcvd = Packet.byte_to_Packet(rcvd_bytes)
if rcvd.magicno == 0x497E: # only run if it works, otherwise packet dropped
acknowledgement_packet = Packet.Packet(0x497E, 1, rcvd.seqno, 0,
'') # rcvd is the received data packet # empty data field
awk_buffer = acknowledgement_packet.convert_to_bytes() # when do we use this?
expected = 1 - expected
if rcvd.data_len > 0:
outfile.write(rcvd.data)
elif rcvd.data_len == 0:
outfile.close()
r_in.close() # unnecessary?
r_out.close()
exit()
else:
# we should test some with weird or missing magicnos, if we havent already
print("Error: invalid magicno. Must be 0x497E")