Write the following code in C for a UNIX system: Two separate programs, a client
ID: 3838741 • Letter: W
Question
Write the following code in C for a UNIX system:
Two separate programs, a client and a server, based on the sample code provided. The client makes a connection to the server and transmits a series of numbers. The server listens for the client communication and when it has received the series of numbers, it adds them together and closes.
Steps:
1) The client needs to know the server IP address and port number. Determine these from the server (no code change from the sample).
2) Client code: Prompt the user for how many numbers to add together, then prompt them for each number. Conversion from string to integer must be done on the client. The server must use a pipe to send received numbers from the child processes to the parent process.
3) Server code: Display each integer immediately after it is entered on the client. When the client is finished sending numbers, the server code should add the numbers together, display the sum, and then exit.
4) Close all sockets on the server and client when you are finished. Make sure all child processes are closed as well.
Sample Code: http://www.cs.rpi.edu/~moorthy/Courses/os98/Pgms/socket.html
Explanation / Answer
Client.c
To compile
and to run
First, we run server.c as in
Then, on client side
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.