-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExp4-sliding-window-protocol.cpp
More file actions
46 lines (42 loc) · 1.03 KB
/
Exp4-sliding-window-protocol.cpp
File metadata and controls
46 lines (42 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Implement Sliding window protocol
#include <iostream>
#include <time.h>
using namespace std;
int main()
{
srand(time(0));
int frames, windowSize;
int transmissions = 0;
cout << "Enter no. of frames to send: ";
cin >> frames;
cout << "Enter the window size: ";
cin >> windowSize;
int i = 1;
while (i <= frames)
{
int ackFrames = 0;
for (int j = i; j < i + windowSize and j <= frames; j++)
{
cout << "Sending frame: " << j << endl;
transmissions++;
}
for (int j = i; j < i + windowSize and j <= frames; j++)
{
int flag = rand() % 2;
if (!flag)
{
cout << "Acknowledgement for frame " << j << " received" << endl;
ackFrames++;
}
else
{
cout << "Frame " << j << " not received" << endl;
cout << "Retransmitting all frames in the window" << endl;
break;
}
}
cout << endl;
i += ackFrames;
}
cout << "Total no. of transmissions: " << transmissions << endl;
}