Thursday, 19 August 2010

Simulation of Sliding Window Protocol

#include"stdio.h"
#include"conio.h"
#include"stdlib.h"

void getdata()
{
FILE *f1;
char c;
clrscr();
printf("\n\t\tEnter the data\n\t\t");
f1=fopen("sc.txt", "w");
while((c=getchar())!='\n')
putc(c, f1);
putc('\n', f1);
fclose(f1);
}


void send()
{
FILE *f1, *f2;
char c;
int i, k=0, windowsize=2, randno, k1;
f1=fopen("sc.txt", "r");
f2=fopen("ms.txt", "w");
loop:
for(i=0; i <>
{
c=getc(f1);
if(c!='\n')
{
printf("%c\n", c);
putc(c, f2);
k++;
}
else
goto end;
}
fclose(f1);
randomize();
randno=random(k);//generates a random number
f1=fopen("sc.txt", "a");
putc(randno, f1);
fclose(f1);
k1=randno;
printf("The Frames of data sent %d\n", k);
getch();
f1=fopen("sc.txt", "r");
fseek(f1, k, SEEK_SET);
goto loop;
end:
fclose(f1);
fclose(f2);
printf("The Frames of data sent %d\n", k);
}

void disp()
{
int choice;
printf("\n\tChoose an option\n");
printf("\n\t1.Send");
printf("\n\t2.Quit");
scanf("%d", &choice);
if(choice==1)
send();
}

void main()
{
clrscr();
getdata();
disp();
getch();
}

No comments:

Post a Comment