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

Sliding

The document contains a C program that implements a sliding window protocol for transmitting frames. It prompts the user for the window size and the number of frames to transmit, then simulates sending the frames and waiting for acknowledgments. The program outputs the frames being sent and indicates when acknowledgments are received after every 'w' frames.

Uploaded by

enjoybaap6
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)
11 views2 pages

Sliding

The document contains a C program that implements a sliding window protocol for transmitting frames. It prompts the user for the window size and the number of frames to transmit, then simulates sending the frames and waiting for acknowledgments. The program outputs the frames being sent and indicates when acknowledgments are received after every 'w' frames.

Uploaded by

enjoybaap6
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

#include <stdio.

h>

int main() {
int w, i, f, frames[50];

printf("Enter window size: ");


scanf("%d", &w);

printf("Enter number of frames to transmit: ");


scanf("%d", &f);

printf("Enter %d frames: ", f);


for (i = 0; i < f; i++) {
scanf("%d", &frames[i]);
}

printf("\nUsing Sliding Window Protocol...\n");


printf("Frames will be sent in the following manner (assuming no corruption):\n\n");
printf("After sending %d frames at each stage, sender waits for ACK from receiver\n\n", w);

for (i = 0; i < f; i++) {


printf("%d ", frames[i]);

// After every 'w' frames, simulate receiving ACK


if ((i + 1) % w == 0) {
printf("\nAcknowledgment received for above frames.\n\n");
}
}

// Handle remaining frames (if f is not divisible by w)


if (f % w != 0) {
printf("\nAcknowledgment received for above frames.\n");
}

return 0;
}

Output

Enter window size: 3


Enter number of frames to transmit: 7
Enter 7 frames: 1 2 3 4 5 6 7
Using Sliding Window Protocol...
Frames will be sent in the following manner (assuming no corruption):

After sending 3 frames at each stage, sender waits for ACK from receiver

123
Acknowledgment received for above frames.

456
Acknowledgment received for above frames.

7
Acknowledgment received for above frames.

You might also like