A C implementation of a data transmission protocol over a serial connection, using a simplified link-layer and application-layer architecture. The project was developed for the Computer Networks course at FEUP.
The project is structured as follows:
.
├── bin/ # Compiled binaries (created after building)
├── include/ # Header files for link and application layers
│ ├── application_layer.h
│ └── link_layer.h
├── src/ # Source code for protocol implementation
│ ├── application_layer.c
│ └── link_layer.c
├── assets/ # Test files used for transmission
│ └── penguin.gif # Default file to send
├── docs/ # Project documentation
│ └── Report_3LEIC12_G1.pdf
├── main.c # Entry point for the application
├── Makefile # Build and run instructions
├── LICENSE # MIT License
└── README.md # Project overview and usage guide
This project is designed to operate on real Linux systems connected via an RS-232 serial cable. However, for ease of testing and demonstration, these instructions use socat to create virtual serial ports on a single machine. You can follow the steps below to set up and test the protocol using virtual ports. If you wish to use actual hardware, simply update the serial port paths in the configuration (e.g., /dev/ttyS0, /dev/ttyS1) to match your physical devices.
Before running the project, you may wish to customize certain settings to match your environment or testing needs. This includes changing serial port paths, selecting a different test file, or adjusting transmission parameters.
Open the Makefile and update these variables as needed:
# Serial port device paths
TX_SERIAL_PORT = /dev/ttyS10 # Transmitter port
RX_SERIAL_PORT = /dev/ttyS11 # Receiver port
# Test file names
TX_FILE = penguin.gif # File to send
RX_FILE = penguin-received.gif # File to receiveTo experiment with different protocol settings, edit the following constants in main.c:
#define BAUDRATE 9600 // Serial communication speed
#define N_TRIES 4 // Number of retransmission attempts
#define TIMEOUT 3 // Timeout (seconds) for retransmissionMake sure to rebuild the project after making changes to the Makefile or source files.
Build the project using the provided Makefile:
$ makeThis compiles all source files in src/ and places the final executable in bin/main.
Run this command in a separate terminal window to create a pair of connected serial ports:
$ sudo socat -d -d PTY,link=/dev/ttyS10,mode=777 PTY,link=/dev/ttyS11,mode=777/dev/ttyS10→ transmitter port/dev/ttyS11→ receiver port
⚠️ Keep this terminal open while testing!The virtual serial ports will remain active only as long as this terminal is running. Closing it will disconnect the ports and interrupt communication.
In a new terminal, start the receiver process:
$ make run_rxThis listens on /dev/ttyS11 and saves the received file as assets/penguin-received.gif.
In another terminal, start the transmitter:
$ make run_txThis sends assets/penguin.gif through /dev/ttyS10.
After the transfer completes, compare the original and received files:
$ make check_filesIf everything worked correctly, you should see:
Files assets/penguin.gif and assets/penguin-received.gif are identical
Remove compiled files and received test data:
$ make cleanThe full project report detailing the protocol design and implementation can be found in
docs/Report_3LEIC12_G1.pdf.
Note: The report is written in Portuguese.
- Afonso Neves ([email protected])
- João Miranda ([email protected])
This project is licensed under the terms of the MIT License.