Starting from:
$30

$24

Homework Assignment 5 Solution

Collaboration Policy. Homeworks will be done individually: each student must hand in their own answers. It is acceptable for students to collaborate in understanding the material but not in solving the problems or programming. Use of the Internet is allowed, but should not include searching for existing solutions.




Under absolutely no circumstances code can be exchanged between students. If some code was shown in class, it can be used, but it must be obtained from Canvas, the instructor or the TA.




Assignments from previous offerings of the course must not be re-used. Violations will be penalized appropriately.




Late Policy. No late submissions will be allowed without consent from the instructor. If urgent or unusual circumstances prohibit you from submitting a homework assignment in time, please e-mail me.




Problem 1. Client-Server Addition (100 points) Create a client-server system that performs addition. The server should listen to port 2000. When the connection with the client is established, the client sends floating point numbers typed by the user to the server. The server adds each number to the sum and sends the sum back to the client. The client displays it.







Hints.




Use the example at the end of the 18th set of notes as the basis of your code. (Make sure to use the pdf posted on 11/28.)



You should include the following header files:



#include <sys/types.h #include <sys/socket.h #include <netdb.h #include <string.h #include <stdio.h #include <stdlib.h #include <unistd.h







You may still need to define a few symbols.



Only ports with numbers above 1023 can be used.


















1



Requirements.




Run the server in the background and the client in the foreground on the same host. This is referred to as the “localhost.”



There is no need to check the data typed in by the user. Assume that they are valid numbers.



Deliverables. A zip/tar/gz file containing:




source files named client.c and server.c.



a script that calls gcc to compile the above files, and then starts the server in the background and the client in the foreground.



















































































































































2

More products