#include <stdio.
h>
int main() {
int windowsize, sent = 0, ack, totalFrames, i;
printf("Enter total number of frames to transmit: ");
scanf("%d", &totalFrames);
printf("Enter window size: ");
scanf("%d", &windowsize);
while (sent < totalFrames) {
// Send up to window size frames or until all frames are sent
for (i = 0; i < windowsize && sent < totalFrames; i++) {
printf("Frame %d has been transmitted.\n", sent);
sent++;
}
printf("\nPlease enter the last Acknowledgement received (0 to %d): ", totalFrames - 1);
scanf("%d", &ack);
if (ack >= totalFrames) {
printf("All frames acknowledged.\n");
break;
} else if (ack < sent) {
sent = ack + 1; // Go back to the frame after last acknowledged
printf("Go-Back-N: Resending from frame %d...\n", sent);
}
}
printf("\nAll frames sent and acknowledged successfully.\n");
return 0;
}
Output
Enter total number of frames to transmit: 6
Enter window size: 3
Frame 0 has been transmitted.
Frame 1 has been transmitted.
Frame 2 has been transmitted.
Please enter the last Acknowledgement received (0 to 5): 1
Go-Back-N: Resending from frame 2...
Frame 2 has been transmitted.
Frame 3 has been transmitted.
Frame 4 has been transmitted.
Please enter the last Acknowledgement received (0 to 5): 4
Frame 5 has been transmitted.
Please enter the last Acknowledgement received (0 to 5): 5
All frames sent and acknowledged successfully.