Protocol Programs for Networking In C Language:-
Protocol 1(Simplex Protocol):-
- It is used for One way sending and receiving technique.
- It doesn't have acknowledgement for sender.
- No correspondence between Sender and Receiver.
Assumption:-
- The channel is error-free.
- The sender is sending from an infinite stream of data and the receiver continues to read what the sender is sending.
- The reciever is at least as fast as the sender, thus we ca run the show without flow control mechanism.
- the sender writes to pipe 1 which is named pipe already defined.
- The write operation is binding operation by default.
Files needed:-
Header Files :- stdio.h, fcntl.h,
sender.txt:- For having message(frames) to send...
sender.txt:- For having message(frames) to send...
sender.c :- Sender side functionality and coding...
receiver.c :- Receiver side functionality and coding...
Code to be typed in sender.c file:
void main()
{
char ch;
char temp[63];
int val = open("pipe1", O_WRONLY);
FILE *fp = fopen("sender.txt","rw+");
system("clear");
while((ch=fgetc(fp))!=EOF)
{
if (ch == ' ')
{
fscanf("%s",temp);
write(val, temp, sizeof(temp));
}
else
{
printf("%s\n",temp);
write(val, temp, sizeof(temp));
}
}
printf("%s\n",temp);
write(val, temp, sizeof(temp));
close(val);
fclose(fp);
}
Code to be typed in Reciever.c file:
void main()
{
int val;
char temp[100];
FILE *fp=fopen("reciever.txt","rw+");
system("clear");
mkfifo("pipe1", 0666, 0);
val = open("pipe1", O_RDONLY);
printf("\nReceiving msg : \n");
while(read(val, temp, sizeof(temp)))
{
printf ("%s\n", temp);
}
}
{
int val;
char temp[100];
FILE *fp=fopen("reciever.txt","rw+");
system("clear");
mkfifo("pipe1", 0666, 0);
val = open("pipe1", O_RDONLY);
printf("\nReceiving msg : \n");
while(read(val, temp, sizeof(temp)))
{
printf ("%s\n", temp);
}
}

About
Tags
Popular


0 comments:
Post a Comment