cachePacket = [] while True: # loops through the window if eotSent == False: for i in xrange(config.windowSize): if resend: # temp = pickle.loads(cachePacket[i]) # print "resending packets: %s" % (temp.seqNum) time.sleep(0.01) socketT.sock.sendall(cachePacket[i]) else: read_data = f.read(1) # pack data in packet print 'sending packet. Sequence Number: %s. Type: %s' % (seqNum, 'Data') packet = MyPacket.mypacket(2, seqNum, read_data, config.windowSize, None) seqNum += 1 # encode packet packet = pickle.dumps(packet) # put packets in the cache array cachePacket.append(packet) # send encoded packet socketT.sock.sendall(packet) # reset variable after for loop resend = False try: # set socket timeout for receiving ack socketT.sock.settimeout(0.01) # wait and receive ack
def sendEot(connection, seqNum): print "Sending FIN" eot = MyPacket.mypacket(3, seqNum, None, config.windowSize, None) eot = pickle.dumps(eot) connection.sendall(eot)
while True: recvBuffer = conn.recv(config.BUFFER_SIZE) if not recvBuffer: break # if there are data if recvBuffer: # decode data recvPacket = pickle.loads(recvBuffer) print "Packet type: ", recvPacket.type # if eot received if recvPacket.type == 3: print "FIN received" # send FIN ACK to transmitter finAck = pickle.dumps(MyPacket.mypacket(3, 1, None, config.windowSize, ackNum+1)) print "sending FIN ACK" conn.sendall(finAck) print "connection closed" # close connection conn.close() break # assign variables data = recvPacket.data seqNum = recvPacket.seqNum ackNum = seqNum + 1 print "packet %s received" % (seqNum) # this packet is not in the buffer window if seqNumInArray(buffWin, seqNum) == False: