Protocol-2 stop-and-wait protocol
header file
/*
Protocol-2 (stop-and-wait) ,
one-directional flow of data from sender to receiver,
error free channel, The receiver has only a finite buffer capacity and a finite
processing speed, protocol must prevent the sender from flooding
*/
#include<stdio.h>
#include<fcntl.h>
#include<string.h>
//define Frame structure
typedef struct
{
int seqno;
int ackno;
char data[100];
}frame;
//services used @ sender side
void from_network_layer(char buffer[],int sno)
{
printf("Enter Frame [%d] : ",sno);
scanf("%s",buffer);
}
void to_physical_layer(frame *f)
{
int pid1;
system(">pipe1");
pid1=open("pipe1",O_WRONLY);
write(pid1,f,sizeof(frame));
close(pid1);
}
void wait_for_event(int seq_no)
{
int pid2,no;
while(1)
{
pid2=open("pipe2",O_RDONLY);
read(pid2,&no,sizeof(no));
if(no==seq_no)
break;
}
close(pid2);
unlink("pipe2");
}
//services used @ reciving side
void from_physical_layer(frame *f)
{
int pid1;
pid1=open("pipe1",O_RDONLY);
read(pid1,f,sizeof(frame));
close(pid1);
unlink("pipe1");
}
void to_network_layer(char buffer[])
{
printf("\nFrame : %s",buffer);
}
void send_ack(int seqno)
{
int pid2;
system(">pipe2");
pid2=open("pipe2",O_WRONLY);
write(pid2,&seqno,sizeof(seqno));
close(pid2);
}
Sender
#include "header.h"
void main()
{
int i,no,pids;
char buffer[100];
frame f;
printf("How many frame you want to send? : ");
scanf("%d",&no);
for(i=0;i<no;i++)
{
from_network_layer(buffer,i);/* get some data from network layer to send next layer */
strcpy(f.data,buffer);/* copy received data into frame's pay load for transmission */
f.seqno=i;
to_physical_layer(&f); /* send our frame on physical layer */
wait_for_event(i); /* block sender until sender received acknowledment from receciver*/
}
}
Receiver
#include "header.h"
void main()
{
int no,i;
char buffer[100];
frame f;
from_physical_layer(&f); /* get some data from physical layer to send network layer */
strcpy(buffer,f.data); /* copy received data into buffer */
to_network_layer(buffer); /* send our received data to network layer */
send_ack(f.seqno); /*send aknowlegment to the sender that we got Frame[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.
1 comments:
nice
Post a Comment