Question
Use the client and server programs,change it so that the client sends an integer to the client. The server multiplies the number by 10 and
Use the client and server programs,change it so that the client sends an integer to the client. The server multiplies the number by 10 and returns the integer*10 back to the client. When writing the integers to the FIFO, use sizeof(int) as the number of bytes in the 3rd parameter of the write( ) and read( ).
//Client Program
#include
main (void) { int fda; // to write to server int fdb; // to read response from server int charbuff[1]; // buffer holds a character int 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("%d", &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! "); }
//Server Program
#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
int charbuff[1]; // buffer holds a character int 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: ,%d", charbuff[0]);
for( i = 0; i<5; i++) outchar[i] = '*'; outchar[5] = charbuff[0]; outchar[6] = 0; printf(" Server: outchar is,%d", 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started