Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!