Question: Modify your client and server programs so that the client sends an integer and an array to the server inside a struct. For the number

Modify your client and server programs so that the client sends an integer and an array to the server inside a struct. For the number of bytes, use sizeof(structName). The server reads the struct (which contains an integer and array) through the FIFO. The server adds the elements of the array (size of less than 10, sent as the integer in the struct). The sum of array elements is written back to the client. Take out all references to the code that is only applicable to the character exchange. Zip together: code for the client, code for the server, and evidence of two runs of your programs.

/*************************** clientTest.c ************************

/

/ opens FIFO_to_server for writing and FIFO_to_client for reading

/

/*********************************************************************/

#include

#include

#include

#include

#include

#include

#include

#include

main (void)

{

int fda; // to write to server

int fdb; // to read response from server

char charbuff[1]; // buffer holds a character

char outchar[7]; // server puts string here

memset(charbuff,0,1);

memset(outchar,0,7);

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

printf("cant open fifo to write");

if((fdb=open("FIFO_to_client", O_RDONLY))<0)

printf("cant open fifo to read");

printf("Client: Please enter a character: ");

scanf("%c", &charbuff);

write(fda, charbuff, 1);

printf(" Client: Got the character sent, now waiting for response ");

read(fdb, outchar, 7);

printf(" Client: received from server %s", outchar);

close(fda);

close(fdb);

printf (" all done! ");

}

/********************************* serverTest.c *****************************

*

* makes 2 fifos named FIFO_to_server and FIFO_to_client

* opens FIFO_to_server for reading and FIFO_to_client for writing

*

**********************************************************************************/

#include

#include

#include

#include

#include

#include

#include

#include

main (void)

{

int fda; // to read from client

int fdb; // to write to client

int finish; // lets me know that client is done

int i; // because C needs this defined as int

char charbuff[1]; // buffer holds a character

char outchar[7]; // server puts string here

memset(charbuff,0,1);

memset(outchar,0,7);

/* Create the fifos and open them */

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

{

perror("cant create FIFO_to_server");

exit(-1);

}

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

{

perror("cant create FIFO_to_client");

exit(-1);

}

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

printf("cant open fifo to write");

if((fdb=open("FIFO_to_client", O_WRONLY))<0)

printf("cant open fifo to read");

finish=read(fda, charbuff, 1); //read the character

printf("Server: just got character: ,%c", charbuff[0]);

for( i = 0; i<5; i++)

outchar[i] = '*';

outchar[5] = charbuff[0];

outchar[6] = 0;

printf(" Server: outchar is,%s", outchar);

write(fdb, outchar, 7);

printf(" Server: Got the characters sent");

if(finish == 1)

printf(" Server: This says I am ready to close ");

close(fda);

close(fdb);

unlink("FIFO_to_server");

unlink("FIFO_to_client");

}

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!