Exercise: Math UDP server

In a previous exercise you programmed a Math TCP server.

In this exercise you must program a Math UDP server.

Protocol design

If you use the same protocol design as you did in the Math TCP server, you might be able to reuse some parts of the Math TCP server code.

However, you are free to change the protocol if you wish.

Server program

Make sure you can read and understand the Echo UDP server.

Make a copy of the Visual Studio Project holding the Echo UDP server (do not modify the original project).

With the Math UDP server you must rework the part of the server where it gives service to the client.

  1. Read the request // like Echo
  2. Split the request into parts // like Math TCP server
  3. Find the operation (ADD, SUB, etc.)
    string.Split(separator) might be useful
  4. Find the numbers
    Double.Parse(numberString) might be useful
  5. Perform the operation on the numbers
  6. Send the response back to the client. // like Echo

Client program

Make a simple client program (preferably Console Application in another Visual Studio solution) to try the Math UDP server.

The client program should be very similar to the Echo UDP client program.

Testing

Use your unit testing framework to test the Math UDP server.

Eventhough this is not exactly unit testing, the unit testing framework is still useful.

The test assumes that the server is running on a known host + port.

The test send a request to the server (very much like the client program) and make assertions about the response.

In the test you can make helper (not TestMethod) method like

Error handling: Bad request

The client may send a bad request, i.e. a request not according to the protocol.

Examples:

In any case the server must send back a proper response for example

You will have to adapt the response part of your protocol AND add more lines to your server.

Trying and testing