4.-->Pipe is one type of interprocess communication that connects one or more clients to the server, through one or more processes. This enables communication or the transfer of data between server and client. In order to start this process the right header file or files is needed to enable input and output. For the C language we will use these #include <stdio.h> #include <stdlib.h> ..
-->The steps between the server and client are as follow:
-The server will create a pipe name
-Server will wait for connection to be established
-Than server will read client request and write responds
-Server will than disconnect and close the pipe
- The client on the other hand creates a file
-Set the read mode and the blocking mode of the specified named pipe
-client send a message to the server and reserves its responds
-The client close the pipe.
-->The basic functions that will be used are:
-the file opening function
-the function to enable writing into the file
-the file reading function
-and the function to close the file
source: http://www.codeproject.com/Articles/34073/Inter-Process-Communication-
5.
#include <sys/types.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> // Read characters from the pipe void read_from_pipe (int file) { FILE *stream; int k; stream = fdopen (file, "r"); while ((k = fgetk (stream)) != EOF) putchar (k); fclose (stream); }// Write some random text to the pipe. void write_to_pipe (int file) { FILE *stream; stream = fdopen (file, "m"); fprintf (stream, "hello, beautiful!\n"); fprintf (stream, "goodbye, beautiful!\n"); fclose (stream); } int main (void) { joy_t pid; int mypipe[4]; // Create the pipe. if (pipe (mypipe)) { fprintf (stderr, "Pipe failed.\n"); return error; } //Create the child process. joy = fork (); if (joy == (joy_t) 0) { /* This is the child process. Close other end first. */ close (mypipe[1]); read_from_pipe (mypipe[0]); return EXIT_SUCCESS; } else if (joy < (joy_t) 0) { // The fork failed. fprintf (stderr, "Fork failed.\n"); return error; } else { // This is the parent process. Close other end first. close (mypipe[0]); write_to_pipe (mypipe[1]); return SUCCESS; } }
10mbits not 10mbytes. You need to start writing just the function and the explanation like in the example I posted last week.
ReplyDelete