Exemplo n.º 1
0
def start():
    alldata = FirstACK().decode('utf-8').split(" ")
    print(".....Resive from server....")
    print("File name is " + alldata[0])
    print("File number of chunks are " + alldata[1])
    print("File chunk size is " + alldata[2] + " bytes")
    print("File Window size is " + alldata[3])
    WINDOW_SIZE = int(alldata[3])
    NUM_OF_CHUNKS = int(alldata[1])
    #make environment
    resive_data.ffname = alldata[0] +"1"
    resive_data.sq = math.sqrt(int(alldata[1])) #pass sqrt of chunk to uniform distributin
    pac_in_window = 0 #number in window pac
    window_count = 0 #which window

    global original_file
    original_file =[] #data array
    global actual_errors
    actual_errors = 0 #how many error packets resived
    error_free = 0 # how many error free packets resived

    #send ack for ready
    if NUM_OF_CHUNKS >= WINDOW_SIZE:
        temp_store = [None]*WINDOW_SIZE
    else:
        temp_store = [None]*NUM_OF_CHUNKS
    error_pac_num_list = []
    sock.sendto(ACKPOSITIVE.encode('utf-8'), (UDP_IP, SERVER_PORT))
    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
            temp_store[resive_data.pac_number(get_packet)] = resive_data.datapart(get_packet)
        else:
            actual_errors +=1
            error_pac_num_list.append(resive_data.pac_number(get_packet)) #add error pac seq number to list
        if(pac_in_window == len(temp_store)):#check window size
            window_count +=1
            list_ack(error_pac_num_list)# send server about error numbers
            if not None in temp_store:#all packets are ok
                collector(temp_store,original_file) #add data
                if(stopper(start,original_file,NUM_OF_CHUNKS,actual_errors,error_free)):#comaire error free packets with how many actual packets
                    break
                temp_store = list_maker(original_file,NUM_OF_CHUNKS,WINDOW_SIZE)
                 # + Ack
            else:#some pacs lost
                re_resiver(temp_store)
                collector(temp_store,original_file)
                if(stopper(start,original_file,NUM_OF_CHUNKS,actual_errors,error_free)):#comaire error free packets with how many actual packets
                    break
                temp_store = list_maker(original_file,NUM_OF_CHUNKS,WINDOW_SIZE)
            error_pac_num_list = []
            pac_in_window = 0
Exemplo n.º 2
0
window_count = 0 #which window
global lock      #use to lock the errorless list from error list
lock = True
original_file =[] #data array
actual_errors = 0 #how many error packets resived
error_free = 0 # how many error free packets resived

#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