/* * This is an example of using a named-pipe for uni-directional communication. * Client (./client) sends strings to the server (./server). You can run the two programs in separate terminals and observe the behavior. * For bi-directional communication, two uni-directional pipes should be used. * To compile: * * g++ named-pipe-client.cpp -o client * g++ named-pipe-server.cpp -o server */ #include #include #include #include #define FIFO_FILE "MYFIFO" using namespace std; int main(void) { FILE *fp; char readbuf[80]; /* Create the FIFO if it does not exist */ umask(0); mknod(FIFO_FILE, S_IFIFO|0666, 0); while(1) { fp = fopen(FIFO_FILE, "r"); fgets(readbuf, 80, fp); cout <<"Received string: "<< readbuf << endl; fclose(fp); } return(0); }