Saturday, February 25, 2012

Write a program for Byte stuffing framing method.(Code for sender and receiver side both)

/* Sender.c - Byte Stuffing*/

#include
#include
#include
main()
{
int fno,i,pid,k=0,j=0;
char str[100],packet[100]="",*ch,str1[100];
ch=(char *)malloc(sizeof(char));
ch[0]='$';
system("clear");
pid=open("pipe",O_WRONLY);
printf("Enter The No. Of Frame : ");
scanf("%d",&fno);
for(i=0;i/* receiver- Byte Stuffing*/

#include
#include
#include
main()
{
int pid,cnt=0,i=1;
char packet[100],ch='$';
system("clear");
mkfifo("pipe",0666);
pid=open("pipe",O_RDONLY);
read(pid,packet,100);
printf("%s\n\n",packet);
while(packet[cnt]!='\0')
{
if(packet[cnt]=='$'&& packet[cnt-1]!=='#')
{
cnt++;
}
else
{
printf("Frame %d : ",i);
i++;
while(packet[cnt]!='$')
{
if(packet[cnt]=='#')
{
cnt++;
}
printf("%c",packet[cnt]);
cnt++;
}
}
printf("\n");
}
close(pid);
unlink("pipe");
}

No comments:

Post a Comment