Write a program with two parts: 1) a client, and

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:

  1. a three-character string representing the operation to be performed, i.e. “add”, “sub”,”div”, and “mul”
  2. the first integer
  3. 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.

Each result packet must consist 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 an 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 in both hardcopy and softcopy (electronic submission): (a) the client program (b) the server program (c) output showing your program works correctly (you can run both the client and the server on the same computer for generating this output)

NOTES: 

1. 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. 

2. Choosing a server port. You will need to run server processes that can coexist with other people’s processes in the same computer. You will need to select an agreed port number for the server to accept messages from clients. Two servers on the same computer cannot use the same local port number. You will therefore need to choose a port number that is different from that of other people. 

 

Leave a Comment

Your email address will not be published. Required fields are marked *

GradeEssays.com
We are GradeEssays.com, the best college essay writing service. We offer educational and research assistance to assist our customers in managing their academic work. At GradeEssays.com, we promise quality and 100% original essays written from scratch.
Contact Us

Enjoy 24/7 customer support for any queries or concerns you have.

Phone: +1 213 3772458

Email: support@gradeessays.com

© 2024 - GradeEssays.com. All rights reserved.

WE HAVE A GIFT FOR YOU!

15% OFF 🎁

Get 15% OFF on your order with us

Scroll to Top