Practical work 2

Practical work 2

Link to the course

L. Delafontaine and H. Louis, with the help of GitHub Copilot.

This work is licensed under the CC BY-SA 4.0 license.

Practical work 2

Objectives

  • Define and implement a network application with TCP and/or UDP
  • Package, publish and run a network application with Docker
  • You can choose what the network application will do (you can be creative!)
    • a chat application, a chess game, a shopping list application, ...
Practical work 2

Demo

More details for this section in the course material.

Practical work 2

Demo 1

A simple file transfer application made with TCP.

Practical work 2
Practical work 2

Compile the project:

./mvnw clean package

Run the CLI without any arguments:

java -jar target/practical-work-2-demo-1-1.0-SNAPSHOT.jar
Missing required subcommand
Usage: DaiFileTransfer [COMMAND]
A simple file transfer application
Commands:
  server  Start a TCP server to serve files
  client  Start a client to download files from a server
Practical work 2

Start the server:

java -jar target/practical-work-2-demo-1-1.0-SNAPSHOT.jar server -p 12345 -t 4

Start the client:

java -jar target/practical-work-2-demo-1-1.0-SNAPSHOT.jar client -p 12345
Practical work 2
  _____          _____   _____           _                  _
 |  __ \   /\   |_   _| |  __ \         | |                | |
 | |  | | /  \    | |   | |__) | __ ___ | |_ ___   ___ ___ | |
 | |  | |/ /\ \   | |   |  ___/ '__/ _ \| __/ _ \ / __/ _ \| |
 | |__| / ____ \ _| |_  | |   | | | (_) | || (_) | (_| (_) | |
 |_____/_/    \_\_____| |_|   |_|  \___/ \__\___/ \___\___/|_|

You are connected to server on port 12345 with IP address localhost.

Available commands:
LS - list available files on server
GET <file> - get file from server
QUIT - quit the client
>
Practical work 2

List available files:

> ls
Available files on server:
demo.txt
my-passwords-in-clear.txt
rzr-sc2.exe

Get one of the available files:

> GET my-passwords-in-clear.txt
Downloading file from server...
File saved to my-passwords-in-clear.txt
Practical work 2

Get a file that does not exist:

> GET not-found.txt
The specified file was not found on the server.

Quit:

> QUIT
Bye.

If a client tries to connect to the server when no thread is available, the client has to wait to be served.

Practical work 2

Demo 2

A weather station application made with UDP.

Practical work 2
Practical work 2

Compile the project:

./mvnw clean package

Run the CLI without any arguments:

java -jar target/practical-work-2-demo-2-1.0-SNAPSHOT.jar
Practical work 2
Missing required subcommand
Usage: practical-work-2-demo-2-1.0-SNAPSHOT.jar [-hV] [COMMAND]
DAI Weather Station
  -h, --help      Show this help message and exit.
  -V, --version   Print version information and exit.
Commands:
  thermometer-emitter      Emits temperature values.
  pressure-emitter         Emits pressure values.
  humidity-emitter         Emits humidity values.
  weather-station          Start an UDP multicast receiver.
  weather-client           Start an UDP weather client.
  list-network-interfaces  List all available network interfaces.
Practical work 2

Start the weather station:

java -jar target/practical-work-2-demo-2-1.0-SNAPSHOT.jar weather-station \
  -i eth0 \
  --port 9876 \
  --server-port 1234

Output:

Multicast receiver started (10.11.12.25:9876)
Unicast receiver started (10.11.12.25:1234)
Practical work 2

Start the emitters:

java -jar target/practical-work-2-demo-2-1.0-SNAPSHOT.jar thermometer-emitter \
  --delay=0 \
  --frequency 10000 \
  -i eth0 \
  -p 9876

java -jar target/practical-work-2-demo-2-1.0-SNAPSHOT.jar pressure-emitter \
  --delay=0 \
  --frequency 10000 \
  -i eth0 \
  -p 9876
Practical work 2

Output:

Emitter of type thermometer started (10.11.12.25:9876).
Multicasting measure : 30.0 to 239.0.0.1:9876 on interface eth0
Multicasting measure : 23.0 to 239.0.0.1:9876 on interface eth0
Multicasting measure : 28.0 to 239.0.0.1:9876 on interface eth0
Multicasting measure : 19.0 to 239.0.0.1:9876 on interface eth0
Multicasting measure : 15.0 to 239.0.0.1:9876 on interface eth0
Emitter of type pressure started (10.11.12.25:9876).
Multicasting measure : 982.0 to 239.0.0.2:9876 on interface eth0
Multicasting measure : 1027.0 to 239.0.0.2:9876 on interface eth0
Multicasting measure : 970.0 to 239.0.0.2:9876 on interface eth0
Multicasting measure : 996.0 to 239.0.0.2:9876 on interface eth0
Multicasting measure : 982.0 to 239.0.0.2:9876 on interface eth0
Practical work 2

Start the weather client:

java -jar practical-work-2-demo-2-1.0-SNAPSHOT.jar weather-client

Output:

Welcome to the weather client!
Please enter the measures you want to get
1. Temperature
2. Humidity
3. Pressure
4. Quit
>

You can then select the measures you want to get.

Practical work 2
> 1
List all measures (1) or only the average? (2)
> 1
----------------------------------------
Received measures: [30.0, 23.0, 28.0, 19.0, 15.0]
----------------------------------------
Please enter the measures you want to get
1. Temperature
2. Humidity
3. Pressure
4. Quit
>

The client will then display all the measures received from the weather station.

Practical work 2
> 3
List all measures (1) or only the average? (2)
> 2
----------------------------------------
Received average: 991.11
----------------------------------------
Please enter the measures you want to get
1. Temperature
2. Humidity
3. Pressure
4. Quit
> 4

The client can then quit the application.

Practical work 2

Group composition

More details for this section in the course material.

Practical work 2

Group composition

  • Two (2) or three (3) students per group.
  • Create a GitHub Discussion to:
    • Announce your group members.
    • Announce your idea (even a draft is fine).
  • You must do it before the next course, otherwise you will be penalized (check the Constraints for details).
Practical work 2

Idea validation

More details for this section in the course material.

Practical work 2

Idea validation

  • You must state your idea on your GitHub Discussion.
  • We might ask you to change your idea if it is too simple or too complex.
  • We will help you to find a good idea if needed.
  • You must do it before the next course!
Practical work 2

Grading criteria

More details for this section in the course material.

Practical work 2

Grading criteria

Based on 25 criteria and a three-point scale:

  • 0 point - The work is missing, off-topic, or shows a very limited understanding of the subject.
  • 0.1 point - The work shows partial understanding: some key elements are missing, unclear, or poorly implemented.
  • 0.2 point - The work is complete, accurate, and shows a clear and thorough understanding of the subject.

Maximum grade: 25 criteria * 0.2 + 1 = 6.

Practical work 2

Constraints

More details for this section in the course material.

Practical work 2

Constraints (1/3)

  • The whole team must contribute to the project and all members must be able to explain it in details if asked.
  • A GitHub Discussion must be opened during the first week of the project to explain the idea of the project so the teachers can validate the idea.
  • The GitHub Discussion must be updated with the link to the repository and a related commit hash before the deadline - every 24 hours after the deadline will result in a -1 point penalty on the final grade.
Practical work 2

Constraints (2/3)

  • You can only use the Java classes seen in the course to implement the network application (you can use any other libraries for other aspects of the application, such as UI, etc.)
  • The application must be slightly more complex and slightly different than the examples presented during the course (we emphasize the word slightly, no need to shoot for the moon).
Practical work 2

Constraints (3/3)

  • You must state your sources if you have used elements that you are not the author (code from the Internet, code generated from AI tools, etc.). You must also state for which usage you did use the source(s)/tool(s) in your README. If you plagiarize the code of another group, all groups involved will receive a grade of 1.
  • Elements that are supposed to be acquired through the teaching unit or previous practical work(s) must not be omitted, forgotten or poorly implemented (you must continue to use the Git/GitHub workflow, allow users to understand your application, etc.).
Practical work 2

Submission

More details for this section in the course material.

Practical work 2

Submission

Your work is due as follows:

  • DAI-TIC-C (Wednesday mornings): Tuesday 02.12.25 at 23:59.
  • DAI-TIC-B (Wednesday afternoons): Tuesday 02.12.25 at 23:59.
  • DAI-TIC-A (Thursdays): Wednesday 03.12.25 at 23:59.

Update the GitHub Discussion with the link to your repository as mentioned in the course material.

If you do not submit your work on time and/or correctly, you will be penalized (-1 point on the final grade for each day of delay).

Practical work 2

Presentations

More details for this section in the course material.

Practical work 2

Presentations

The practical work presentations will take place on:

  • DAI-TIC-C (Wednesday mornings): Wednesday 03.12.25 starting at 10:30 in room TBD
  • DAI-TIC-B (Wednesday afternoons): Wednesday 03.12.25 starting at 14:45 in room TBD
  • DAI-TIC-A (Thursdays): Thursday 04.12.25 starting at 16:30 in room TBD

The exact schedule will be communicated once the groups are known.

Practical work 2

Grades and feedback

Grades will be entered into GAPS, followed by an email with the feedback.

The evaluation will use exactly the same grading grid as shown in the course material.

Each criterion will be accompanied by a comment explaining the points obtained, a general comment on your work and the final grade.

If you have any questions about the evaluation, you can contact us!

Practical work 2

Tips

More details for this section in the course material.

Practical work 2

Create diagrams

  • You can use any tools you want to create your diagrams:

PDF, PNG, SVG, etc. are all accepted formats in your repository.

Practical work 2

Extract the command and parameters from the message

The Short Message Service (SMS) protocol presented in the "Define an application protocol" course defines the following message:

RECEIVE <message> <username>

This message is sent by the server to a client to inform them that they have received a message from another user.

Practical work 2

The command is RECEIVE and the parameters are <message> and <username>.

The message can be up to 100 characters long.

You can use the following snippet of code to extract the command and the parameters from the message:

Practical work 2
List<String> messageParts = Arrays.asList(emitterMessage.split(" ", 2));

String command = messageParts.get(0);
switch (command) {
  // Other cases can be defined here...
  case "RECEIVE" -> {
    if (messageParts.size() < 2) {
      // Invalid message, do something about it such as logging it or returning an error...
    }

    List<String> parameters = Arrays.asList(messageParts.get(1).split(" "));

    if (parameters.size() < 2) {
      // Invalid message, do something about it such as logging it or returning an error...
    }

    String user = parameters.removeLast();
    String message = String.join(" ", parameters);

    System.out.printf("Message from %s: %s\n", user, message);
    break;
  }
  // Other cases can be defined here...
}
Practical work 2

The POSIX standard

The Portable Operating System Interface (POSIX) standard is a family of standards specified by the IEEE Computer Society for maintaining compatibility between operating systems. POSIX defines both the system and user-level application programming interfaces (APIs), along with command line shells and utility interfaces, for software compatibility (portability) with variants of Unix and other operating systems.

https://en.wikipedia.org/wiki/POSIX

Practical work 2

Questions

Do you have any questions?

Practical work 2

Find the practical work

You can find the practical work for this part on GitHub.

Practical work 2

Finished? Was it easy? Was it hard?

Can you let us know what was easy and what was difficult for you during this practical work?

This will help us to improve the course and adapt the content to your needs. If we notice some difficulties, we will come back to you to help you.

➡️ GitHub Discussions

You can use reactions to express your opinion on a comment!

Practical work 2

Sources

(Un)comment the following lines to hide/show the note about the presentations

### Presentations (2/2) We only have **8 minutes per group**. You decide what you want to show us and how you want to present it. **Come 5 minutes before your time slot** with your computer. You will have access to a video projector. The presentation order is random and is stated in the next tables: - [DAI-TIC-C (Wednesday mornings)](<https://github.com/heig-vd-dai-course/heig-vd-dai-course/blob/main/06.02-practical-work-2-(1-of-6)/01-course-material/README.md#dai-tic-c-wednesday-mornings>) - [DAI-TIC-B (Wednesday afternoons)](<https://github.com/heig-vd-dai-course/heig-vd-dai-course/blob/main/06.02-practical-work-2-(1-of-6)/01-course-material/README.md#dai-tic-b-wednesday-afternoons>) - [DAI-TIC-A (Thursdays)](<https://github.com/heig-vd-dai-course/heig-vd-dai-course/blob/main/06.02-practical-work-2-(1-of-6)/01-course-material/README.md#dai-tic-a-thursdays>)

(Un)comment the following lines to hide/show the note about the presentations