Warm-Up Exercise: Socket Based Communication


Exercise

This exercise is not part of the marked CW Demo is but part of the report discussion and therefore highly recommended to:

  • refresh programming skills
  • understand ideas and inner-workings behind ROS

For this work you will use Microsoft Visual Studio 2019 (or another version, if you wish).

Generate Two Programs Using Python (or C++)

(#1) Write a program that acts as server processing unit (a simple calculator).

(#2) Write a second program that acts as user interface (can be graphical if you wish) as a client “requester” program (e.g. an interface)

These two programs will send/receive messages to request calculations (#2) and respond with results (#1).

The communication will see the processing unit (#1) being the Server and (#2) an User Interface (e.g. GUI) as the Client receiving the user input and requesting computation from (#1).

Use sockets to establish communication and design a suitable protocol.


Hints on steps to follow:

  1. Create a server that can handle at least a client.
  2. The server will function as calculator (minimum operational requirements are +, -, *, /, ^, sqrt).
  3. Create a client that can receive commands from a user.
  4. Receive and send commands (you will need to create your own protocol and/or parser to decode the strings).
  5. Use the client interface to send commands to the “calculator process”.
  6. Send back the result and display it.
  7. The connection and performances need to be good and reliable, and transparency should be provided.
  8. Inconsistent or wrong expression should trigger errors and be logged (e.g. on screen, or even better in a .txt file).
  9. Measure of success at least 2 wrong expressions detected and 3 correct inputs solved.

Further hints:

  1. You can start with stand-alone applications.
  2. Building the programs as state machines will help.
  3. Create a pseudo code and/or an operational diagram and/or state machine.
  4. Keep it simple - the focus is on understanding the inter-processes communication, not to make a fully functioning scientific calculator or creating a perfect user interface.