0% found this document useful (0 votes)
25 views2 pages

4b Program in CPP For Selective Repeat

The document contains a C++ program that implements the selective repeat sliding window protocol for data transmission. It simulates sending frames, receiving acknowledgments, and handling timeouts for retransmission. The program prompts the user for the total number of frames and the window size, then outputs the transmission process and the total number of frames sent and resent.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views2 pages

4b Program in CPP For Selective Repeat

The document contains a C++ program that implements the selective repeat sliding window protocol for data transmission. It simulates sending frames, receiving acknowledgments, and handling timeouts for retransmission. The program prompts the user for the total number of frames and the window size, then outputs the transmission process and the total number of frames sent and resent.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

/* 4b program in cpp for selective repeat sliding window protocol */

#include<bits/stdc++.h>
#include<ctime>

#define ll long long int


using namespace std;

void transmission(ll & i, ll & N, ll & tf, ll & tt)


{
while (i <= tf)
{
int z = 0;
for (int k = i; k < i + N && k <= tf; k++)
{
cout << "Sending Frame " << k << "..." << endl;
tt++;
}
for (int k = i; k < i + N && k <= tf; k++)
{
int f = rand() % 2;
if (!f)
{
cout << "Acknowledgment for Frame " << k << "..." << endl;
z++;
}
else
{
cout << "Timeout!! Frame Number : " << k << " Not Received" << endl;
cout << "Retransmitting frame..." << k << endl;
break;
}
}
cout << "\n";
i = i + z;
}
}

int main()
{
ll tf, N, tt = 0;
srand(time(NULL));
cout << "Enter the Total number of frames : ";
cin >> tf;
cout << "Enter the Window Size : ";
cin >> N;
ll i = 1;
transmission(i, N, tf, tt);
cout << "Total number of frames which were sent and resent are : " << tt <<
endl;
return 0;
}
Sample output

Enter the Total number of frames : 6


Enter the Window Size : 3
Sending Frame 1...
Sending Frame 2...
Sending Frame 3...
Acknowledgment for Frame 1...
Acknowledgment for Frame 2...
Timeout!! Frame Number : 3 Not Received
Retransmitting frame...3

Sending Frame 3...


Sending Frame 4...
Sending Frame 5...
Acknowledgment for Frame 3...
Acknowledgment for Frame 4...
Acknowledgment for Frame 5...

Sending Frame 6...


Timeout!! Frame Number : 6 Not Received
Retransmitting frame...6

Sending Frame 6...


Acknowledgment for Frame 6...

Total number of frames which were sent and resent are : 8

You might also like