Vote count:
0
I am writing a program which simulates the RDT 3.0 protocol (alternating bit protocol). I am stuck at the part where we are supposed to resend the packet after timeout if no ack was received from the receiver. There is a send method, where the data packet is send to the receiver and receives back the ack from it. I have declared and scheduled the task there(as shown below):
byte[] info;
int len;
int seqNum;
Timer timer = new Timer();
timer.schedule(new timeOut(info,len, seqNum), 5000);
The timer is canceled if the ack is not received and is not corrupted. Then i have created a class within the sender class which needs to resend the packet, which was not acked. So this class is shown below:
class timeOut extends TimerTask{
byte[] info;
int len;
int seqNum;
timeOut(byte[] temp, int length, int seqNo){
info = temp;
len = length;
seqNum = seqNo;
}
public void run (){
//i am not sure on how to resend the packet again at this part
send(info,seqNum);
}
}
I tried calling the send method in the RDT Sender directly, it is not working (gives an error). I also tried creating the data packet and sending it, this gives me an error too. The first error is not clear, as it just indicates the line causing the problem. In the second case, the error is related to the timer (Timer-1, null pointer exception). However, i feel that the second example is not right. The send method is shown below:
//send the packet
DataPacket pkt = new DataPacket(info, len, seqNo);
udt.send(p);
//timer starts when the packet is send
Timer timer = new Timer();
timer.schedule(new timeOut(info,len, seqNum), 5000);
// receive the ACK from receiver
AckPacket ack = udt.recieve();
if(p.length != 0 && !ack.isCorrupted && ack.ack == seqNumber){**
System.out.println("Complete");
timer.cancel();
}
Sorry for the long post, was trying to be as informative as possible. Thank you for your time and help, guys!
Aucun commentaire:
Enregistrer un commentaire