Computer Networks Lab: Delhi Technological University
Computer Networks Lab: Delhi Technological University
Computer Networks Lab: Delhi Technological University
THEORY: Stop and Wait transmission is the simplest reliability technique and is adequate for a
very simple communications protocol. A stop and wait protocol transmits a Protocol Data Unit
(PDU) of information and then waits for a response. The receiver receives each PDU and sends an
Acknowledgement (ACK) PDU if a data PDU is received correctly, and a Negative Acknowledgement
(NACK) PDU if the data was not received. In practice, the receiver may not be able to reliably
identify whether a PDU has been received, and the transmitter will usually also need to implement
a timer to recover from the condition where the receiver does not respond.
CODE:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<bits/stdc++.h>
using namespace std;
int main()
{
int i,j,noframes,x,x1=10,x2;
//clrscr();
for(i=0;i<200;i++)
rand();
noframes=rand()/200;
i=1;
j=1;
noframes = noframes / 10;
printf("\n number of frames is %d",noframes);
cout<<endl;
getch();
while(noframes>0)
{
printf("\nsending frame %d",i);
cout<<endl;
srand(x1++);
x = rand()%10;
if(x%2 == 0)
{
for (x2=1; x2<2; x2++)
{
printf("waiting for %d seconds\n", x2);
cout<<endl;
//sleep(x2);
}
printf("\nsending frame %d",i);
cout<<endl;
srand(x1++);
x = rand()%10;
}
printf("Acknowledgement for frame %d",j);
cout<<endl;
noframes-=1;
i++;
j++;
}
printf("\n end of stop and wait protocol");
cout<<endl;
getch();
}
OUTPUT: