Tuesday, 16 October 2012

Sliding Window Protocols using C



#include<fstream.h>
#include<stdio.h>
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<process.h>
void receiver(char a,int& flag)
{

fstream fil;
fil.open("Z:\write.txt",ios::in|ios::app);
cout<<"\nThe receive bit is :"<<a;
fil<<a;
flag=1;
fil.close();
getch();

}
void sender()
{
int flag=0;
fstream f;
f.open("Z:\send.txt",ios::in|ios::app);
char a=1;
while(!f.eof())
{
     f>>a;
     cout<<"\nsending bit is:";
     cout<<a;
     receiver(a,flag);
     if(flag==0)
     {
getch();
exit(0);
     }
     cout<<"\nacknowledgement complete NEXT BIT :\n";
     flag=0;
}
}
void main()
{
clrscr();
remove("Z:\CN\write.txt");
sender();
getch();
}

/* OUTPUT:
sending bit is:G
The receive bit is :G
acknowledgement complete NEXT BIT :

sending bit is:O
The receive bit is :O
acknowledgement complete NEXT BIT :

sending bit is:O
The receive bit is :O
acknowledgement complete NEXT BIT :

sending bit is:D
The receive bit is :D
acknowledgement complete NEXT BIT :

sending bit is:M
The receive bit is :M
acknowledgement complete NEXT BIT :

sending bit is:O
The receive bit is :O
acknowledgement complete NEXT BIT :

sending bit is:R
The receive bit is :R
acknowledgement complete NEXT BIT :

sending bit is:I
The receive bit is :I
acknowledgement complete NEXT BIT :

sending bit is:N
The receive bit is :N
acknowledgement complete NEXT BIT :

sending bit is:G
The receive bit is :G
acknowledgement complete NEXT BIT :

*/