Skip to content

Commit 2c6e4e1

Browse files
committed
Receiver function for Go-Back-N Algorithm
1 parent f03e203 commit 2c6e4e1

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

Go-Back-N/GoBackN.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,22 @@ void GoBackN::sender() {
4444

4545
cout << "*** Sender: All frames sent successfully ***\n";
4646
}
47-
47+
48+
// Receiver function for Go-Back-N algorithm
49+
void GoBackN::receiver() {
50+
while (frame_expected < MAX_SEQUENCE_NUM) {
51+
cout << "Waiting for frame " << frame_expected << "...\n";
52+
53+
bool frame_arrives = rand() % 2;
54+
55+
if (frame_arrives) {
56+
cout << "Frame " << frame_expected << " received\n";
57+
cout << "Sending acknowledgment: " << frame_expected << endl;
58+
frame_expected++;
59+
} else {
60+
cout << "*** Timeout occurred, requesting retransmission ***\n";
61+
}
62+
}
63+
64+
cout << "*** Receiver: All frames received successfully ***\n";
65+
}

Go-Back-N/GoBackN.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class GoBackN {
1616
public:
1717
GoBackN(int window_size);
1818
void sender();
19+
void receiver();
1920
};
2021

2122
#endif

0 commit comments

Comments
 (0)