-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgoback2.cpp
More file actions
49 lines (36 loc) · 1.05 KB
/
Copy pathgoback2.cpp
File metadata and controls
49 lines (36 loc) · 1.05 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
47
48
49
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
const int MAX_FRAMES = 100;
int main() {
int numFrames, windowSize;
int totalFramesSent = 0;
srand(time(NULL));
cout << "Enter the total number of frames: ";
cin >> numFrames;
cout << "Enter the window size: ";
cin >> windowSize;
int currentFrame = 1;
while(currentFrame <= numFrames) {
int numSent = 0;
for(int i = currentFrame; i < currentFrame + windowSize && i <= numFrames; i++) {
cout << "Sending frame " << i << endl;
totalFramesSent++;
numSent++;
}
for(int i = currentFrame; i < currentFrame + numSent && i <= numFrames; i++) {
int ack = rand() % 2;
if(ack) {
cout << "Acknowledgment received for frame " << i << endl;
} else {
cout << "Timeout occurred for frame " << i << endl;
cout << "Retransmitting window..." << endl;
break;
}
}
currentFrame += numSent;
}
cout << "Total number of frames sent and resent: " << totalFramesSent << endl;
return 0;
}