
GEORGE MASON UNIVERSITY
Computer Science Department
CS 571 – Operating Systems
Assignment 3 – Client-Server Programming using Sockets and RPC/RMI
1. Implementing an arithmetic server using sockets Write a program with two parts: 1) a
client, and 2) an arithmetic server.
The job of the client is to accept input from the keyboard and translate strings that you type
into requests to the arithmetic server. In other words, the client should translate strings such
as “3 + 4” into a request to the arithmetic server. The format of the request packet sent by
the client to the server is follows. Each packet consists of three fields: (i) a three-character
string representing the operation to be performed, i.e. “add”, “sub”,”div”, and “mul” (ii)
the first integer (iii) the second integer. Note that the size of each request packet (in bytes)
will depend upon the representation of characters and integers in the language you’re using
for this assignment. In C, a character is represented in one byte and an integer in four bytes.
The server should parse each packet, extract the parameters of the request, perform the
requested operation and transmit the results to the client, which then prints out the results
on the screen. The arithmetic server should implement the procedures add, subtract, multiply,
and divide. Each of these procedures should accept two integers as input and return an integer
as a result. In addition, the divide procedure must detect an attempted “divide by zero” and
return an error code.
The format of a result packet is as follows. Each result packet consists of two fields. The
first field is an integer that takes the values 0 or 1, where 1 represents a successful operation
whereas 0 represents a unsuccessful operation (e.g. divide by 0). The second field is an
integer corresponding to the result of the arithmetic operation or an error code representing
the reason for the error. (For example, you can use the integer 1 to represent “divide by
zero”.)
There are two versions of this program you have to implement
1. The client and server communicate using UDP.
2. The client and server communicate using TCP.
You have to submit to me: (a) the client program (b) the server program (c) output show-
ing your program works correctly (you can run both the client and the server on the same
computer for generating this output)
NOTES:
1. You can use Java or C/C++ for this assignment. You can reuse most of the code in the
example programs available on the assignment web page.
2. It is not acceptable to translate integers into a string for transmitting them over the network.
Your packets must follow the formats specified in the description above.
1