Exemple #1
0
def stopper(start,ori_file,CH,actual_errors,error_free):
    if(len(ori_file)==CH):
        end = time.time()# now file transfer is over
        resive_data.print_All(str(end - start),actual_errors,error_free)#print results
        resive_data.writer(ori_file)#create a file
        return True
    return False
Exemple #2
0
#send ack for ready
sock.sendto(ACKPOSITIVE.encode('utf-8'), (UDP_IP, 5005))
start = time.time()

while True:
    data, addr = sock2.recvfrom(2048) # buffer size is 2048 bytes
    get_packet = pickle.loads(data) #load data from packet
    pac_in_window +=1
    if resive_data.error(get_packet,pac_in_window-1):#check the errors
        error_free += 1
        if(lock):# can add data to array
            original_file.append(resive_data.datapart(get_packet))
            if(len(original_file) == NO_OF_CH ):#comaire error free packets with how many actual packets
                end = time.time()# now file transfer is over
                resive_data.print_All(str(end - start),actual_errors,error_free)#print results
                resive_data.writer(original_file)#create a file
                break
    else:
        if(lock):
            error_in_pac = resive_data.window_number(get_packet) #get the first error packet
        lock = False    #ignore all data after the error
        actual_errors +=1
    if(pac_in_window == WINDOW_SIZE):#check window size
        window_count +=1
        if(lock):
            window_Ack(ACKPOSITIVE) # + Ack
        else:
            window_Ack(str(error_in_pac))#- Ack with wrong window number
            error_list = [] #free the list
            lock = True