Last active
September 2, 2016 04:55
-
-
Save sks147/1cf94201ca89f073e21059110dbd928e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Simulating selective repeat sliding window protocol | |
#include <iostream> | |
#include <cstdlib> | |
using namespace std; | |
void receiver(int r); | |
int sent_packets=0; | |
int received_packets=0; | |
bool ack; | |
void sender() | |
{ | |
int buffer[10]; | |
for(int i=0;i<10;i++) | |
{ | |
buffer[i]=sent_packets+1; | |
sent_packets++; | |
cout<<"sending packet "<<buffer[i]<<endl; | |
receiver(buffer[i]); | |
while(!ack) | |
{ | |
cout<<"resending packet "<<buffer[i]<<endl; | |
receiver(buffer[i]); | |
} | |
} | |
if(sent_packets<200) | |
sender(); | |
} | |
void receiver(int r) | |
{ | |
int num=rand()%50; | |
if(num>15) | |
{ | |
cout<<"Received packet "<<r<<endl; | |
received_packets++; | |
ack=true; | |
} | |
else | |
{ | |
ack=false; | |
cout<<"error"<<endl; | |
} | |
} | |
int main() { | |
sender(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment