A Possible Implementation of the Remote TCP-Based Calculator Exercise for the Computer Networks Subject
This is a Rust language implementation for a programming task of the Computer Networks subject of the Bachelor Degree in Telecommunication Technologies Engineering of the Universidade de Vigo.
As the exercise involves a very basic socket communication scenario, the code tries to provide a minimally satisfactory solution without consideration to performance or security whatsoever.
The client and server programs are contained in the files tcp1cli.rs and tcp1ser.rs. They make use of a little library for parsing the arithmetic operations both from the user and from/to the network.
The file operations.rs defines the allowed set of arithmetic operations, the functions to calculate them and all the conversions needed: from TLV fields and to from strings for exchanging data with the user.
Finally, a set of utilities for managing TLVs are provided in the file tlv.rs.
All the encoding and decoding methods have been performed manually, instead of using a crate like serde as this was something that students are expected to learn how to do it in this exercise. Obviously, if this were not an exercise, it would have been more adequate to not try to reinvent the wheel.
Even if the spirit was to do as much of the code ourselves, we have used some dependencies for the tasks not directly related with the communication problem. The list is as follows:
- anyhow and thiserror: For easy error management and definition, respectively.
- clap: To parse command line arguments.
- regex: To parse the operations as entered by the user
- socket2: We needed to use this low-level socket library in the
server to make the Windows version of the program behave like the Linux
one. We use a IPV6 socket on the server to accept both IPv4 and IPv6
connections. Under Linux this works by default, but in windows this has to
be enabled manually. Two alternative solutions would have been:
- Ignoring the issue and accepting only IPv6 connections under Windows,
- use simultaneous sockets in the server, but this complicates the code so much.
Copyright ⓒ 2023–2025 Universidade de Vigo.
Author: Miguel Rodríguez Pérez [email protected].
This software is licensed under the GNU General Public License, version 3 (GPL-3.0) or later. For information see LICENSE.