I have a problem in my socket program(trying to implement sliding window algorithm). Details are given below:
I have declared a static member variable ServerWindow of type Vector in my socket program. I am adding all the packets receiving from the client to this vector. But whenever I am trying to add a new packet, it simply overwrites all the records in the vector. So my vector when displayed has the last packet for all elements. I have checked the received packet and its contents are OK.
public void receive(DatagramPacket p) throws IOException {
boolean KeepRunning = true;
boolean KeepGoing = true;
ServerWindow = new Vector();
while(KeepRunning){
try{
while (KeepGoing){
if (ServerWindow.size() <= 7){
super.receive(p);
if (isCorrectCRC(p)){//checking CRC
ServerWindow.add(p);
}
}
if (ServerWindow.size() == 7){
for (i=0;i<ServerWindow.size();i++){
System.out.println("In receive(): " + i + " " + new String( (byte[])ServerWindow.get(i)));
}
}
}
}catch(SocketTimeoutException e){
} //end of catch
} // end of while
} // end of receive method
I have declared a static member variable ServerWindow of type Vector in my socket program. I am adding all the packets receiving from the client to this vector. But whenever I am trying to add a new packet, it simply overwrites all the records in the vector. So my vector when displayed has the last packet for all elements. I have checked the received packet and its contents are OK.
public void receive(DatagramPacket p) throws IOException {
boolean KeepRunning = true;
boolean KeepGoing = true;
ServerWindow = new Vector();
while(KeepRunning){
try{
while (KeepGoing){
if (ServerWindow.size() <= 7){
super.receive(p);
if (isCorrectCRC(p)){//checking CRC
ServerWindow.add(p);
}
}
if (ServerWindow.size() == 7){
for (i=0;i<ServerWindow.size();i++){
System.out.println("In receive(): " + i + " " + new String( (byte[])ServerWindow.get(i)));
}
}
}
}catch(SocketTimeoutException e){
} //end of catch
} // end of while
} // end of receive method