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:
- Create a server that can handle at least a client.
- The server will function as calculator (minimum operational requirements are +, -, *, /, ^, sqrt).
- Create a client that can receive commands from a user.
- Receive and send commands (you will need to create your own protocol and/or parser to decode the strings).
- Use the client interface to send commands to the “calculator process”.
- Send back the result and display it.
- The connection and performances need to be good and reliable, and transparency should be provided.
- Inconsistent or wrong expression should trigger errors and be logged (e.g. on screen, or even better in a .txt file).
- Measure of success at least 2 wrong expressions detected and 3 correct inputs solved.
Further hints:
- You can start with stand-alone applications.
- Building the programs as state machines will help.
- Create a pseudo code and/or an operational diagram and/or state machine.
- 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.