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;
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
def carry_on(exit_flag, inputfile, next1, num_of_packets): 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() return next1
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)
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")