minitalk is a 42 School project focused on creating a small data exchange program using UNIX signals. The project consists of a client and server that communicate using only SIGUSR1 and SIGUSR2 signals.
"A simple but powerful implementation of inter-process communication using signals."
The goal is to transmit any string from a client program to a server program using only UNIX signals as the communication method.
- Implement a communication protocol using only UNIX signals
- Create a client that can send messages to a server
- Create a server that can receive and display messages
- Handle the transmission of strings of any length
- Implement proper error handling and signal management
- Learn about processes, signals, and bitwise operations
The project consists of three main components:
minitalk/
├── inc/
│ └── minitalk.h # Header file with prototypes and includes
├── src/
│ ├── client.c # Client implementation
│ └── server.c # Server implementation
└── Makefile # Compilation instructions
The header file includes:
- Standard library includes
- Custom function prototypes
- Wait time definition for signal transmission
- Utility function declarations
The client program sends messages to the server:
Function | Description |
---|---|
pid_error | Validates command line arguments and PID format |
send_ch_by_bit | Sends a single character by breaking it into 8 bits |
send_len_by_bit | Sends string length as 32 bits to prepare the server |
main | Parses arguments and orchestrates the message transmission |
The server program receives and displays messages from clients:
Function | Description |
---|---|
recive_len | Reconstructs the length of the incoming message from bits |
recive_str | Reconstructs characters from bits and builds the final string |
recive_client_data | Signal handler that processes incoming signals |
main | Displays PID, sets up signal handlers, and waits for client connections |
-
Connection Establishment:
- Server starts and displays its PID
- Client uses the server's PID to target signal transmission
-
Message Transmission:
- Client first sends the string length (32 bits) to the server
- Server allocates memory based on the received length
- Client sends each character of the string (8 bits per character)
- Server reconstructs each character and builds the complete message
-
Bit Encoding:
- SIGUSR1 represents bit value 1
- SIGUSR2 represents bit value 0
- Bits are sent sequentially with a delay between signals
- Binary data transmission using only two signals
- Support for messages of any length
- Error handling for invalid PIDs
- Memory management for received strings
- Bitwise operations for encoding/decoding messages
- Process management and inter-process communication
- Signal handling in UNIX systems
- Bitwise operations and binary data manipulation
- Memory management
- Protocol design and implementation
Metric | Value |
---|---|
Final Score | 80/100 |
Lines of Code | ~150 |
Signal Types | 2 (SIGUSR1, SIGUSR2) |