Beispiel #1
0
def transfer():
    windowframe = 0 #window frame number
    i =0 #chunk increasere
    NO_OF_CHUNKS = datahandle.no_of_chun(SEND_FILE, CHUNK_SIZE)
    temp_store = []
    while True:
        if(windowframe == WINDOW_SIZE ):
            windowframe = 0
            k = lst_maker(ack_listener())
            if(len(k)!= 0):
                #print("******")
                print("Negative ack resive")
                #i = i - ((int(k) + WINDOW_SIZE) * CHUNK_SIZE )#re arrange the window in data buffer
                #print(temp_store)
                resender(temp_store,k)
                temp_store = []
            else:
                print("Positive ack resive")
                temp_store = []
                #k = ACKPOSITIVE
        if i > CHUNK_SIZE*NO_OF_CHUNKS:
            #print("Chunk chunk "+str(i))
            i = i - CHUNK_SIZE
        data_part = data_to_send[i:i+CHUNK_SIZE]
        i += CHUNK_SIZE
        packet={windowframe:{data_part.__hash__():data_part}} #add data and metadata to dictionary hash value of data
        send_packet = pickle.dumps(packet) #make one packet
        temp_store.append(send_packet)#make temp store in window
        try:
            sock2.sendto(send_packet,(UDP_IP, CLIENT_PORT)) #send data
        except Exception:
            print("Connection error")
            break
        #print("frame " + str(windowframe) + " send")
        windowframe +=1
Beispiel #2
0
        temp_store.append(send_packet)#make temp store in window
        try:
            sock2.sendto(send_packet,(UDP_IP, CLIENT_PORT)) #send data
        except Exception:
            print("Connection error")
            break
        #print("frame " + str(windowframe) + " send")
        windowframe +=1

print("Server IP " + UDP_IP +" Srever port "+ str(UDP_PORT))
print("Window size is "+ str(WINDOW_SIZE))
print("Chunk size is "+ str(CHUNK_SIZE))
print("Ready to connect......")

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP
sock.bind((UDP_IP, UDP_PORT))
# resiver
sock2 = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

data_to_send = datahandle.get_data(SEND_FILE)#get data array
firstdata = datahandle.get_file_info(SEND_FILE, CHUNK_SIZE) + " " + str(WINDOW_SIZE)#first information

sendACK(firstdata)#check the connection of the server and send send data about the file
print(datahandle.no_of_chun(SEND_FILE, CHUNK_SIZE))
#file_size = len(data_to_send)#get the size of the file from bytes
WAIT() #wait till the resiver ready to get data

transfer()