Programming assignment 1

Basic network programming

DUE: Oct. 21, 2008, 2pm

This assignment is meant to give you practice building a simple client-server program using sockets. You will write a server that provides a basic calculator service for clients. The server should accept connections from clients and expect to receive a message from a client composed of:

A single character operation to perform (eg: +,-,/,*) followed by the operands as two double precision numbers (NOT ASCII text).

The server should then perform the computation and send the result back to the client. You must design the response format to deal with errors on the server side, such as a computation that results in a divide by zero. The client should print the result (or error) that it received from the server.

An example transaction would be a client sending a plus followed by two double precision numbers representing 1.0 and 2.0. The server should respond with a 3.0. Similarly, a client sending a division operator followed by a one and a zero should receive an error from the server. The server should be able to accept connections after an erroneous computation occurs, and not die with a divide by zero exception.

The client and server must be run on different machines. The hostname and port of the server must be specified on the client command line. The port name of the server must similarly be command line specified. You will implement this both using TCP and UDP sockets. In the UDP case, you should take into account the possibility of lost datagrams.

Update: I got a couple questions to clarify the above. Here are the answers for all to see.

You will be expected to turn in (electronically, by e-mail):

Feel free to use either Java or C. The code must compile on either Solaris (ix), Linux, or MacOSX.