1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
svlad2 [7]
3 years ago
11

Write a client program that writes a struct with a privateFIFO name (call it FIFO_XXXX, where XXXX is the pid that you got from

the getpid( ) function) to the server. Have the server read the privateFIFO name and write a message back to the client. Read the message and print it on the client side
Computers and Technology
1 answer:
ivann1987 [24]3 years ago
3 0

Answer:

client code:

#include <stdio.h>

#include <fcntl.h>

#include <sys/stat.h>

#include <sys/types.h>

#include <unistd.h>

#include <stdlib.h>

#include <string.h>

int main (void)

{

 struct values

 {

   char privateFIFO[14];

   int intbuff;

 }input;

 int fda;  // common FIFO to read to write to server

 int fdb;      // Private FIFO to read from server

 int clientID;

 int retbuff;

 char temp[14];

 clientID = getpid();

 strcpy(input.privateFIFO, "FIFO_");

 sprintf(temp, "%d", clientID);

 strcat(input.privateFIFO, temp);

 printf("\nFIFO name is %s", input.privateFIFO);

 // Open common FIFO to write to server

 if((fda=open("FIFO_to_server", O_WRONLY))<0)

    printf("cant open fifo to write");

 write(fda, &input, sizeof(input));    // write the struct to the server

 close(fda);

 // Open private FIFO to read

 if((fdb=open(input.privateFIFO, O_RDONLY))<0)

    read(fdb, &retbuff, sizeof(retbuff));

 printf("\nAll done\n");

 close(fdb);

}

server code:

#include <stdio.h>

#include <errno.h>

#include <fcntl.h>

#include <sys/stat.h>

#include <sys/types.h>

#include <unistd.h>

#include <stdlib.h>

#include <string.h>

struct values

 {

   char privateFIFO[14];

   int intbuff;

 }input;

int main (void)

{

 int fda;  //common FIFO to read from client

 int fdb;  //private FIFO to write to client

 int retbuff;

 int output;

// create the common FIFO  

 if ((mkfifo("FIFO_to_server",0666)<0 && errno != EEXIST))

       {

       perror("cant create FIFO_to_server");

       exit(-1);

}

// open the common FIFO

 if((fda=open("FIFO_to_server", O_RDONLY))<0)

    printf("cant open fifo to write");

output = read(fda, &input, sizeof(input));

// create the private FIFO

 if ((mkfifo(input.privateFIFO, 0666)<0 && errno != EEXIST))

 {

   perror("cant create privateFIFO_to_server");

   exit(-1);

 }

 printf("Private FIFO received from the client and sent back from server is: %d", output);

 //open private FIFO to write to client

if((fdb=open(input.privateFIFO, O_WRONLY))<0)

   printf("cant open fifo to read");

 write(fdb, &retbuff, sizeof(retbuff));

 close(fda);

 unlink("FIFO_to_server");

 close(fdb);

 unlink(input.privateFIFO);

}

Explanation:

You might be interested in
What type of software is an antivirus?
Kamila [148]

Answer: what type of software is an antivirus?

Answer: A security software

Explanation:

Antivirus software is a type of security software designed to protect users from multiple types of malware, not just viruses. The software is a risk management tool that scans devices regularly and on-demand for known malware and suspicious behavior associated with malware.

6 0
2 years ago
Read 2 more answers
Find the area of square whose perimeter is 260.8m​
inessss [21]
4251.04

The perimeter (260.8) over 4 is equal to each side length (65.2)

65.2^2 = 4251.04
5 0
2 years ago
Can anyone help me with this coding?
Snezhnost [94]

Answer:

Need more details properly.

Explanation:

Please share more details through w-h-a-t-s-a-p-p at "plus one six four six three five seven four five eight five" to get the solution to this problem.

Thanks!

6 0
3 years ago
A puppy weighed 6 ounces at birth. After two weeks, the puppy weighed 14 ounces. How much did the puppy gain? Model the equation
ivann1987 [24]
+8 ounces ...don't know what an alrebra tile so I just subtracted :)
7 0
2 years ago
Read 2 more answers
Which best describes the benefits of renting a home?
arlik [135]
The benefit of actually growing up.
5 0
3 years ago
Other questions:
  • Famed science fiction writer H. G. Wells once envisioned something to store vast amounts of information. What did he call it?
    15·2 answers
  • Jeff wants to print quickly so he presses the Ctrl and the P. Jeff used a _____. macro invoice template shortcut
    15·1 answer
  • Most Microsoft Windows fatal errors (blue screen of death) are caused by:
    14·1 answer
  • Is it okay to leave your car running while parked?
    15·1 answer
  • What type of information is kept on a database?
    10·1 answer
  • To print a range of cells in the active worksheet, click___ in the settings in print gallery.
    7·1 answer
  • Several disaster relief nonprofits want to create a centralized application and repository of information so that they can effic
    7·1 answer
  • Why is dark supereffective against ghost?
    5·2 answers
  • Which of the following number is divisible by 3? (340 , 432 , 113)​
    7·1 answer
  • Define foreign employment​
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!