Protocol 3 A Simplex Protocol for a Noisy Channel
header.h
#include<stdio.h>
#include<fcntl.h>
#include<string.h>
//define Frame structure
struct frame
{
int frame_type;//{1-frame, 0-ack}
int seqno;
int ackno;
char data[50];
};
//services used @ sender side
void from_network_layer(char buffer[])
{
printf("\nEnter Data : ");
scanf("%s",buffer);
}
void to_physical_layer(struct frame *f)
{
int pid1;
system(">pipe1");
pid1=open("pipe1",O_WRONLY);
write(pid1,f,sizeof(struct frame));
close(pid1);
if(f->frame_type==1)
{
printf("\n\n\tFrame [%d]-[%s] sucessfully send.\n",f->seqno,f->data);
}
else
{
printf("\n\n\tAcknowledment [%d]-[%s] sucessfully send.\n",f->ackno,f->data);
}
}
int get_ack()
{
int pid2,ackno=0;
pid2=open("pipe2",O_RDONLY);
if(pid2>0)
{
read(pid2,&ackno,sizeof(ackno));
unlink("pipe2");
}
close(pid2);
return ackno;
}
int start_timer(int seqno)
{
printf("\nTimer Starts");
int i=1,flag=1;
for(i=1;i<=10;i++)
{
sleep(1);
if(seqno==get_ack())
{
flag=0;
break;
}
printf("\ntime : %d ",i);
}
return flag;
}
//services used @ reciving side
void from_physical_layer(struct frame *f)
{
int pid1;
pid1=open("pipe1",O_RDONLY);
f->seqno=0;
if(pid1>0)
{
read(pid1,f,sizeof(struct frame));
unlink("pipe1");
}
close(pid1);
}
void to_network_layer(struct frame *f)
{
printf("\n\nframe No [ %d ]-[%s]received successfully\n",f->seqno,f->data);
}
void send_ack(int seqno)
{
int pid2;
system(">pipe2");
pid2=open("pipe2",O_WRONLY);
if(pid2>0)
{
write(pid2,&seqno,sizeof(seqno));
}
close(pid2);
}
sender
#include "header.h"
void main()
{
int no,i;
char buffer[50];
struct frame f;
printf("Enter How Many Frame you want to send : ");
scanf("%d",&no);
for(i=1;i<=no;i++)
{
from_network_layer(buffer);
strcpy(f.data,buffer);
f.seqno=i;
f.frame_type=1;
do
{
to_physical_layer(&f);
}while(start_timer(f.seqno));
}
//send ack for terminate the connection
strcpy(f.data,"terminate");
f.seqno=-1;
f.ackno=1;
f.frame_type=0;
to_physical_layer(&f);
}
receiver
#include "header.h"
void main()
{
int no,i,frame_expected=1;
char buffer[50];
struct frame f;
while(1)
{
sleep(1);
from_physical_layer(&f);
if(f.seqno!=frame_expected)
{
if(f.seqno==-1)
{
printf("\n\nTransmision Compilted...\n Total [ %d ] frame received\n\n",frame_expected-1);
break;
}
else
{
printf("\nwaiting for frame [ %d ]",frame_expected);
send_ack(f.seqno);
continue;
}
}
else
{
frame_expected++;
strcpy(buffer,f.data);
to_network_layer(&f);
send_ack(f.seqno);
}
}
}
Subscribe to:
Post Comments (Atom)
Subjects
- WordPress
- Mobile Computing-4649303 Practical Solution
- Android Programming New Syllabus Theory
- PHP LAMP Question Bank
- PHP LAMP Theory
- Step by Step Android Example
- Android Practical
- Android Theory
- Android Question Bank
- Networking FON Practical
- Networking FON Theory
- OS Practical
- OS Theory
- HTML
- JavaScript
- J2EE WTAD Theory
- J2EE WTAD Question Bank
- J2EE WTAD Quick Guide
- J2EE WTAD GTU Papers
- J2EE WTAD Practical
- Python
- JAVA Theory
- JAVA Practical
- MIS
Categories
- Android (55)
- c (11)
- Configure Tomcat7 (2)
- CSS (3)
- Decryption (16)
- Difference (1)
- Encryption (16)
- Error Detection and Correction Techniques (3)
- FON (27)
- Framing Technic (2)
- install Tomcat (2)
- J2EE (29)
- JAVA (13)
- JavaScript (19)
- linux (8)
- OS (17)
- PHP (11)
- Protocol (3)
- SERVER SOCKET PROGRAMING (7)
- Servlet (13)
- shell script (33)
- unix (22)
- WTAD (34)
Total Pageviews
© BipinRupadiya.com. Powered by Blogger.
0 comments:
Post a Comment