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 two Python data structures are already thread-safe, because they provide automatic support for synchronizing multiple reade
murzikaleks [220]

The  two Python data structures that are already thread-safe are list and tuples.

<h3>What are the data structures in Python?</h3>

Python is known to give room for its users to make  their own Data Structures.

It helps one to be able to  have total hold or control over their work or output functionality. Some key Data Structures are Stack, Queue, and others.

Learn more about Python from

brainly.com/question/26497128

#SJ1

6 0
2 years ago
In this chapter, we use the metaphor of a blueprint and houses that are createdfrom the blueprint to describe classes and object
Pachacha [2.7K]

Answer:

The correct answer to the following question will be Classes.

Explanation:

Class:

  • Class and objects are the two basic concepts of Object-oriented programming language (Oops).
  • A prototype by which an object can be created.
  • A Class is a collection of data members and member functions.
  • A Class is a user-defined blueprint on an object.
  • Declaration of a class includes: Class names, modifiers, Super class, interfaces and body
8 0
3 years ago
What's the keyboard command that will allow you to "copy" text?
lana66690 [7]

For mac/apple operating systems; command c to copy command v to paste

For windows operating systems; control c to copy control v to paste

4 0
3 years ago
Read 2 more answers
"a web client that connects to a web server, which is in turn connected to a bi application server, is reflective of a"
Bingel [31]

The web client that connects to a web server, which is in turn connected to a bi-application server, is reflective of a one-tier architecture.

<h3>What is a website?</h3>

A website is a collection of web pages and related material that is published on at least one server and given a shared domain name.

A one-tier architecture is reflected in the web application that connects to a web server, which is coupled to a bi-application server.

Thus, the web client that connects to a web server, which is in turn connected to a bi-application server, is reflective of a one-tier architecture.

Learn more about the website here:

brainly.com/question/19459381

#SPJ4

8 0
2 years ago
Which method would you use to get the value associated with a specific key and remove that key-value pair from the dictionary
ollegr [7]

Answer:

popitem

items

pop

list

Explanation:

5 0
2 years ago
Other questions:
  • To insert a new slide in an existing presentation, what menu should you select?
    5·2 answers
  • Use the RSA cipher with public key n = 713 = 23 · 31 and e = 43. Encode the word "KING" into its numeric equivalent and encrypt
    15·1 answer
  • A is a paid placement that appears in a search engines results page at or near the top of the results
    5·1 answer
  • The _________ indicates the number of elements, or values, an array can hold
    14·1 answer
  • The variable most_recent_novel is associated with a dictionary that maps the names of novelists to their most recently published
    12·1 answer
  • Given an initialized String variable outfile, write a statement that declares a PrintWriter reference variable named output and
    12·1 answer
  • Answer the queston...........​
    7·2 answers
  • The graph shows households in the world with internet access from 2003 to 2019. A graph titled Percentage of Households with Int
    6·2 answers
  • Why do we need to make a plan before actions?
    7·1 answer
  • Write the use of these computers.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!