Programs Experts Community Question Online Exam ResourceLink Gallery Members Search
Login
Username:
Password:
New user? Sign up
Forgot Password?
Notice
New Category Started

Question, Resource &
Rich Text Editor
for content text input
Invite Friends
Email *
Firstname *
Lastname
 
Programmer Information
View Source Code
stop and wait protocol by shridatt zambodker
/*Stop and wait protocol*/
#include<stdio.h>
int timer=0,waitack=-1,frameq=0,f=0,i,cansend=1;
main()
{
    int framet[3];
/*Entering time at which te frame is ready*/
    printf("Enter the time at which the frame is ready. ");
    for(i=0;i<3;i++)
    {
        scanf("\n %d",&framet[i]);
        printf("\n framet[ %d ] is %d.\n",i,framet[i]);
    }
    /*main timer-maintains the value and count througout*/
    for(i=0;i<=20;i++)
    {
        sender(i,&framet);
        receiver();
    }
    return 0;
}


sender(int i,int *framet)
    {
        printf("The value of i is %d .",i);
        /*Checking whether the count equals the time at which the frame
s ready-that is if i is 0 and whether there is a frame ready at that time*/
        if(i==framet[f])
        {
            frameq++;
            f++;
        }
        /*Checking whether frames are ready to send*/
        if(frameq==0)
        {
            printf("\n There are no frames to send. \n");
        }
        /*if cansend is 1,a frame can be sent
         * a frame can only be sent if frameq>0 that is there are frames
ready in d frameq to be sent
         * and if cansend is 1*/
        if((frameq>0)&cansend==1)
        {
            printf("\n Frame sent at time %d. \n",i);
            /*increaments timer when the frame is sent to keep track*/
            timer++;
            /*frameq is decremented since 1 frame is sent*/
            frameq--;
            /*cansend is made 0 so that another frame cant be sent
             * and since the acknowledgement for the previous frame
has not yet been received*/
            cansend=0;
        }
        if(waitack>-1)
                {
                printf("\n The acknowledgement has not yet ben received. \n");
                waitack++;
                if(waitack==3)
                {
                    printf("\n The ack is received.\n");
                    cansend=1;
                }
                }
                return 0;
    }

receiver()
{
    printf("\n  The timer value in the receiver 5d. %d \n",timer);
if(timer==0)
{
printf("\n The frame has not beensent.\n");
}
if(timer>0)
{
    timer++;
}
if(timer==3)
{
printf("\n  The frame arrived at time %d. \n",i);
waitack=0;
timer=0;
}
else
{
printf("\n  waiting for frameat time %d.. \n",timer);
}

}
Views
18

Rating
0

Language
C

Category
Miscellaneous

Compiler
CC

OS
Any

Last Modified
13th Jan 10 04:49:23 AM

View Program Documentation
Rating, Comments, Suggestions & Bugs
Additional Feaures

 
© Scodz, 2006 All Rights Reserved. Guest Book | FAQ | Privacy Policy | Terms & Conditions | Contact Us  
Contact Us for Advertising in this website