Showing posts with label Simplex Protocol. Show all posts
Showing posts with label Simplex Protocol. Show all posts

12 Apr 2014

Protocol 1 Program..


Protocol Programs for Networking In C Language:-



Protocol 1(Simplex Protocol):-

  1. It is used for One way sending and receiving technique.
  2. It doesn't have acknowledgement for sender.
  3. No correspondence between Sender and Receiver.

Assumption:-

  1. The channel is error-free.
  2.  The sender is sending from an infinite stream of data and the receiver continues to read what the sender is sending.
  3. The reciever is at least as fast as the sender, thus we ca run the show without flow control mechanism.
  4. the sender writes to pipe 1 which is named pipe already defined.
  5. 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.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);
        }

}

Comments

© 2013-2016 ITTechnocrates. All rights resevered. Developed by Bhavya Mehta