Sliding Window Protocol Program in C and C++

Here you will get a sliding window protocol program in C.

In PC systems sliding window, the protocol is a technique to transmit information on a system.

Sliding window protocol is applied to the Data Link Layer of the OSI model. At information connection layer information is as edges.

In Networking, Window basically implies a cradle which has information outlines that should be transmitted.

Both sender and recipient concur on some window size. In the event that window size=w, at that point subsequent to sending

w outlines sender hangs tight for the affirmation (ack) of the principal outline.

When the sender gets the affirmation of a casing it is supplanted by the following edges to be transmitted by the sender.

On the off chance that beneficiary sends a group or aggregate affirmation to sender, at that point it comprehends

that more than one casings are appropriately gotten, for eg:- if ack of edge 3 is gotten

it comprehends that casing 1 and casing 2 are gotten appropriately.

In sliding window protocol the beneficiary must have some memory to remunerate

any misfortune in transmission or if the casings are gotten unordered.

Effectiveness of Sliding Window Protocol

η = (W*tx)/(tx+2tp)

W = Window Size

tx = Transmission time

tp = Propagation delay

Sliding window works in full duplex mode

It is of two kinds:-

Particular Repeat: Sender transmits just that casing which is incorrect or is lost.

Return n: Sender transmits all casings present in the window that happens after the blunder bit including mistake bit too.

Sliding Window Protocol Program in C

The following is the creation of sliding window protocol in C.

#include<stdio.h>
 
int main()
{
    int w,i,f,frames[50];
 
    printf("Enter window size: ");
    scanf("%d",&w);
 
    printf("\nEnter number of frames to transmit: ");
    scanf("%d",&f);
 
    printf("\nEnter %d frames: ",f);
 
    for(i=1;i<=f;i++)
        scanf("%d",&frames[i]);
 
    printf("\nWith sliding window protocol the frames will be sent in the following manner (assuming no corruption of frames)\n\n");
    printf("After sending %d frames at each stage sender waits for acknowledgement sent by the receiver\n\n",w);
 
    for(i=1;i<=f;i++)
    {
        if(i%w==0)
        {
            printf("%d\n",frames[i]);
            printf("Acknowledgement of above frames sent is received by sender\n\n");
        }
        else
            printf("%d ",frames[i]);
    }
 
    if(f%w!=0)
        printf("\nAcknowledgement of above frames sent is received by sender\n");
 
    return 0;
}

Output

Enter window size: 3

Enter number of frames to transmit: 5

Enter 5 frames: 12 5 89 4 6

With sliding window protocol the frames will be sent in the following manner (assuming no corruption of frames)

After sending 3 frames at each stage sender waits for acknowledgement sent by the receiver

12 5 89
Acknowledgement of above frames sent is received by sender

4 6
Acknowledgement of above frames sent is received by sender

Sliding Window Protocol Program in C++

#include<iostream>
 
using namespace std;
 
int main()
{
    int w,i,f,frames[50];
 
    cout<<"Enter window size: ";
    cin>>w;
 
    cout<<"\nEnter number of frames to transmit: ";
    cin>>f;
 
    cout<<"\nEnter "<<f<<" frames: ";
 
    for(i=1;i<=f;i++)
        cin>>frames[i];
 
    cout<<"\nWith sliding window protocol the frames will be sent in the following manner (assuming no corruption of frames)\n\n";
    cout<<"After sending "<<w<<" frames at each stage sender waits for acknowledgement sent by the receiver\n\n";
 
    for(i=1;i<=f;i++)
    {
        if(i%w==0)
        {
            cout<<frames[i]<<"\n";
            cout<<"Acknowledgement of above frames sent is received by sender\n\n";
        }
        else
            cout<<frames[i]<<" ";
    }
 
    if(f%w!=0)
        cout<<"\nAcknowledgement of above frames sent is received by sender\n";
 
    return 0;
}

Remark beneath in the event that you have any inquiries with respect to the above program.

Recent Posts

error: Alert: Content is protected!!