Write A Program To Implement Sliding Window: Experiment No. 8 Aim: Theory
Write A Program To Implement Sliding Window: Experiment No. 8 Aim: Theory
Write A Program To Implement Sliding Window: Experiment No. 8 Aim: Theory
THEORY:
As soon as sender receives the acknowledgement of a frame it is replaced by the next frames
to be transmitted by the sender. If receiver sends a collective or cumulative acknowledgement
to sender then it understands that more than one frames are properly received, for eg:- if ack
of frame 3 is received it understands that frame 1 and frame 2 are received properly.
In sliding window protocol the receiver has to have some memory to compensate any loss in
transmission or if the frames are received unordered.
Algorithm
1. Transmit all frames in the sender's window (no more than from to )
2. Whenever the receiver gets a frame in its window:
1. it generates an ACK for the highest frame correctly received (same as the
frame for protocol 5).
2. if the frame has been received it passes to the host and bumps
and (advances the window).
3. Whenever the receiver gets a damaged frame or a frame not within its window it
generates a NAK for one less than the frame expected ( ) (only for protocol
6).
4. Whenever the sender receives an ACK for a frame within its window, it marks that
frame as having been correctly sent and received. If is ACKed then increment
and (advance the sender's window) and transmit (last previously unsent
frame).
5. Whenever a timer goes off, retransmit the corresponding frame.
Code:
#include<stdio.h>
int main()
{
int w,i,f,frames[50];
for(i=1;i<=f;i++)
scanf("%d",&frames[i]);
printf("\nWith sliding window protocol the frames will be sent in the following manner
(assuming no corruption of frames)\n\n");
printf("After sending %d frames at each stage sender waits for acknowledgement sent by
the receiver\n\n",w);
for(i=1;i<=f;i++)
{
if(i%w==0)
{
printf("%d\n",frames[i]);
printf("Acknowledgement of above frames sent is received by sender\n\n");
}
else
printf("%d ",frames[i]);
}
if(f%w!=0)
printf("\nAcknowledgement of above frames sent is received by sender\n");
return 0;
}
Output: