Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Minitalk

A client-server communication program using UNIX signals for data transmission.

Description

Minitalk is a project that explores inter-process communication using UNIX signals. It consists of a server that receives messages and a client that sends messages, communicating entirely through SIGUSR1 and SIGUSR2 signals. The server can handle multiple clients sequentially.

Features

  • Client-server architecture using signals only
  • Bit-by-bit data transmission
  • Unicode support
  • Multiple client handling
  • Acknowledgment system
  • Error handling and timeout protection

Components

Server

  • Displays its PID upon startup
  • Receives messages from clients
  • Prints received messages to stdout
  • Handles multiple clients sequentially

Client

  • Sends messages to server using server PID
  • Transmits data bit by bit using signals
  • Receives acknowledgments from server

Compilation

make

This creates two executables: server and client.

Usage

  1. Clone the repository:
git clone https://github.com/bratzwitch/minitalk.git
cd minitalk
  1. Compile the programs:
make
  1. Start the server:
./server

The server will display its PID (e.g., Server PID: 12345).

  1. Send a message from client:
./client [SERVER_PID] "Your message here"

Example

Terminal 1 (Server):

$ ./server
Server PID: 12345
Waiting for messages...
Hello from client!
Another message

Terminal 2 (Client):

$ ./client 12345 "Hello from client!"
Message sent successfully!
$ ./client 12345 "Another message"
Message sent successfully!

How It Works

Signal Communication

  • SIGUSR1: Represents bit 0
  • SIGUSR2: Represents bit 1

Data Transmission Process

  1. Client converts each character to binary
  2. Sends each bit as a signal (SIGUSR1 or SIGUSR2)
  3. Server receives signals and reconstructs the character
  4. Server sends acknowledgment back to client
  5. Process repeats for each character

Example of 'A' (ASCII 65 = 01000001):

Client → Server: SIGUSR1 (0)
Client → Server: SIGUSR2 (1)
Client → Server: SIGUSR1 (0)
Client → Server: SIGUSR1 (0)
Client → Server: SIGUSR1 (0)
Client → Server: SIGUSR1 (0)
Client → Server: SIGUSR1 (0)
Client → Server: SIGUSR2 (1)
Server reconstructs: 'A'

File Structure

  • server.c: Server implementation
  • client.c: Client implementation
  • minitalk.h: Header file with prototypes
  • utils.c: Helper functions (if any)
  • Makefile: Compilation rules

Implementation Details

Server

void sig_handler(int sig, siginfo_t *info, void *context)
{
    static int bit = 0;
    static char c = 0;
    static pid_t client_pid = 0;
    
    // Handle signal and reconstruct character
    // Send acknowledgment to client
}

Client

void send_char(pid_t server_pid, char c)
{
    int bit;
    
    for (bit = 7; bit >= 0; bit--)
    {
        if ((c >> bit) & 1)
            kill(server_pid, SIGUSR2);
        else
            kill(server_pid, SIGUSR1);
        usleep(100); // Small delay for reliability
    }
}

Error Handling

  • Invalid PID validation
  • Signal sending failures
  • Server timeout handling
  • Memory allocation errors
  • Invalid arguments

Testing

Basic functionality:

./client [PID] "Hello, World!"
./client [PID] "Test with numbers: 12345"
./client [PID] "Special chars: !@#$%^&*()"

Unicode support (bonus):

./client [PID] "Unicode: 你好 🌟 Émojis"

Stress testing:

./client [PID] "$(cat large_file.txt)"

Bonus Features

If implemented:

  • Unicode character support
  • Acknowledgment system between client and server
  • Multiple client handling with queuing

Requirements

  • GCC compiler
  • Make
  • UNIX-like system (Linux, macOS)
  • Understanding of UNIX signals

Signals Used

  • SIGUSR1: User-defined signal 1 (represents bit 0)
  • SIGUSR2: User-defined signal 2 (represents bit 1)
  • SIGACTION: For advanced signal handling (bonus)

Performance Considerations

  • Small delays between signals for reliability
  • Acknowledgment system to prevent data loss
  • Timeout handling for robustness

Author

Viacheslav Moroz - 42 Student

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages