Simulate and implement selective repeat sliding window protocol in Computer Network -KML Tutorial

 Aim:- Simulate and implement selective repeat sliding window protocol.

Program:-

  1. #include<stdio.h>
  2. int main()
  3. {
  4.     int w,i,f,frames[50];
  5.     printf("Enter window size: ");
  6.     scanf("%d",&w);
  7.     printf("\nEnter number of frames to transmit: ");
  8.     scanf("%d",&f);
  9.     printf("\nEnter %d frames: ",f);
  10.     for(i=1;i<=f;i++)
  11.         scanf("%d",&frames[i]);
  12.     printf("\nWith sliding window protocol the frames will be sent in the following manner (assuming no corruption of frames)\n\n");
  13.     printf("After sending %d frames at each stage sender waits for acknowledgment sent by the receiver\n\n",w);
  14.     for(i=1;i<=f;i++)
  15.     {
  16.         if(i%w==0)
  17.         {
  18.             printf("%d\n",frames[i]);
  19.             printf("Acknowledgment of above frames sent is received by sender\n\n");
  20.         }
  21.         else
  22.             printf("%d ",frames[i]);
  23.     }
  24.     if(f%w!=0)
  25.         printf("\nAcknowledgment of above frames sent is received by sender\n");
  26.     return 0;
  27. }

Outpute:-

Enter window size: 2

Enter number of frames to transmit: 3

Enter 3 frames: 1
2
3

With sliding window protocol the frames will be sent in the following manner (assuming no corruption of frames)

After sending 2 frames at each stage sender waits for acknowledgment sent by the receiver

1 2
Acknowledgment of above frames sent is received by sender

3
Acknowledgment of above frames sent is received by sender

Comments