Structure Query Language, C programming, Java, Servlet, Jsp, Unix

Tuesday 12 June 2012

Unrestricted Simplex Protocol- Protocol 1

[ HEADER.H ]

#include<stdio.h>
#include<fcntl.h>
#include<string.h>
typedef struct 
{
int seqno;
int ackno;
char data[50];
}frame;
void from_network_layer(char buffer[])
{
printf("Enter Data : ");
scanf("%s",buffer);
}
void to_physical_layer(int pid1,frame *f)
{
write(pid1,f,sizeof(frame));
}
void from_physical_layer(int pid1,frame *f)
{
read(pid1,f,sizeof(frame));
}
void to_network_layer(char buffer[])
{
printf("\n%s",buffer);
}



[ SENDER SIDE ]

#include<stdio.h>
#include<fcntl.h>
#include<string.h>
#include "header.h"
void main()
{
int pid1,i,no;
char buffer[50];
frame f;
system(">pipe1");
pid1=open("pipe1",O_WRONLY);
printf("Enter NUMBER OF DATA : ");
scanf("%d",&no);
write(pid1,&no,sizeof(no));
for(i=0;i<no;i++)
{
from_network_layer(buffer);
strcpy(f.data,buffer);
to_physical_layer(pid1,&f);
}
close(pid1);
}

[ RECEIVER SIDE ]


#include<stdio.h>
#include<fcntl.h>
#include<string.h>
#include "header.h"
void main()
{
int pid1,no,i;
char buffer[50];
frame f;
pid1=open("pipe1",O_RDONLY);
read(pid1,&no,sizeof(no));
printf("DATA RECEIVED : %d",no);
printf("\nDATA");
for(i=0;i<no;i++)
{
from_physical_layer(pid1,&f);
strcpy(buffer,f.data);
to_network_layer(buffer);
}
close(pid1);
unlink("pipe1");
}


6 comments:

  1. All these programs are tested under GCC compiler in linux mint. By changing some of the things like opening file in read only mode or write only mode as of Turbo C syntax we can run it in windows as well.
    Happy Coding..

    ReplyDelete
    Replies
    1. hello sir...im trying to simulate it but it is not giving correct answer..do i need any specific simulator for this??

      Delete
    2. No, it doesn't need any specific simulator but it is simple c program and tested in gcc, may be problem is of temporary file, check it whether data write from sender is correctly written to file or not. and make sure u run sender first and check it and then check for receiver side.

      All The Best Programmer. :)

      Delete
  2. how to connect the sender program in one pc to the reciever program in another and use this unrestricted simplex protocol to send a frame from one pc to another via wifi

    ReplyDelete
  3. hello aditya,

    For reading a file from another computer you have to use RMI in C.
    After that you can read pipe file created from sender.

    Happy Coding.


    ReplyDelete