Simulate and implement stop and wait protocol for noisy channel in Computer Network -KML Tutorial
Aim:- Simulate and implement stop and wait protocol for noisy channel.
Program:-
- #include<stdio.h>
- #include<stdlib.h>
- #include<time.h>
- int main(){
- int n,i=0,sn=0,rn=0,proba=0;
- srand(time(0));
- printf("Enter the number of frames:");
- scanf("%d",&n);
- while(i<n){
- sn=i%2;
- printf("Sender: sending frame no. %d with sequence number %d\n",i,sn);
- proba=rand()%100;
- if(proba>80){
- printf("****Frame is corrupted****\n");
- }else{
- if(sn==rn){
- rn=(rn+1)%2;
- printf("Receiver: sending acknowledgment No. %d\n",rn);
- proba=rand()%100;
- if(proba>80){
- printf("****Acknowledgment frame corrupted****\n");
- }else{
- i++;
- }
- }else{
- printf("Receiver: sending acknowledgment No. %d\n",rn);
- proba=rand()%100;
- if(proba>80){
- printf("**Acknowledgment frame corrupted**\n");
- }else{
- i++;
- }
- }
- }
- }
- return 0;
- }
Outpute:-
Enter the number of frames:5
Sender: sending frame no. 0 with sequence number 0
Receiver: sending acknowledgment No. 1
Sender: sending frame no. 1 with sequence number 1
****Frame is corrupted****
Sender: sending frame no. 1 with sequence number 1
Receiver: sending acknowledgment No. 0
Sender: sending frame no. 2 with sequence number 0
Receiver: sending acknowledgment No. 1
Sender: sending frame no. 3 with sequence number 1
Receiver: sending acknowledgment No. 0
Sender: sending frame no. 4 with sequence number 0
Receiver: sending acknowledgment No. 1
Comments
Post a Comment