Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write comments to eachline of code #include #include #include #include #include #define FIFO_FILE_1 /tmp/client_to_server_fifo #define FIFO_FILE_2 /tmp/server_to_client_fifo int main() { int client_to_server; int server_to_client; char

Write comments to eachline of code

#include #include #include #include #include

#define FIFO_FILE_1 "/tmp/client_to_server_fifo" #define FIFO_FILE_2 "/tmp/server_to_client_fifo"

int main() { int client_to_server; int server_to_client; char buf[BUFSIZ];

/* create the FIFO (named pipe) */ mkfifo(FIFO_FILE_1, 0666); mkfifo(FIFO_FILE_2, 0666);

printf("Server ON. ");

while (1) { /* open, read, and display the message from the FIFO */ client_to_server = open(FIFO_FILE_1, O_RDONLY); server_to_client = open(FIFO_FILE_2, O_WRONLY);

read(client_to_server, buf, BUFSIZ);

if (strcmp("$",buf)==0) { printf("Server OFF. "); break; }

else if (strcmp("",buf)!=0) { printf("Received: %s ", buf); printf("Sending back... "); write(server_to_client,buf,BUFSIZ); }

/* clean buf from any data */ memset(buf, 0, sizeof(buf));

}

close(client_to_server); close(server_to_client);

unlink(FIFO_FILE_1); unlink(FIFO_FILE_2); return 0; } client

#include #include #include #include #include #include #include #include #include

#define FIFO_FILE_1 "/tmp/client_to_server_fifo" #define FIFO_FILE_2 "/tmp/server_to_client_fifo"

int main() { system("clear"); int client_to_server; int server_to_client;

char str[140];

printf("Input message to server: "); scanf("%139[^ ]", str);

/* write str to the FIFO */ client_to_server = open(FIFO_FILE_1, O_WRONLY); server_to_client = open(FIFO_FILE_2, O_RDONLY);

if(write(client_to_server, str, sizeof(str)) < 0){ perror("Write:");//print error exit(-1); } if(read(server_to_client,str,sizeof(str)) < 0){ perror("Read:"); //error check exit(-1); } printf(" ...received from the server: %s ",str);

close(client_to_server); close(server_to_client);

return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

JDBC Database Programming With J2ee

Authors: Art Taylor

1st Edition

0130453234, 978-0130453235

More Books

Students also viewed these Databases questions

Question

What appraisal intervals are often used in appraisal reviews?

Answered: 1 week ago

Question

What are the stages of project management? Write it in items.

Answered: 1 week ago

Question

why do consumers often fail to seek out higher yields on deposits ?

Answered: 1 week ago

Question

=+What is the nature of the unions in the particular country?

Answered: 1 week ago