Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

minitalk

A 42 school project: two programs, server and client, that exchange a text message using nothing but UNIX signals (SIGUSR1 / SIGUSR2) — no sockets, pipes, shared memory, or files.

How it works

  • The client sends the message to the server one bit at a time: SIGUSR1 for a 1 bit, SIGUSR2 for a 0 bit, least-significant bit first, 8 signals per byte.
  • The server's signal handler accumulates 8 incoming signals into a byte and write()s it to stdout as soon as it has a full byte — the message appears on the server's terminal as it's received.
  • Since the protocol just moves raw bytes (not "ASCII characters"), multi-byte UTF-8 text — accented letters, emoji, non-Latin scripts — comes through correctly too: each byte of the UTF-8 encoding is simply sent as its own group of 8 signals.

Mandatory vs. bonus

Mandatory (server / client) Bonus (server_bonus / client_bonus)
Byte transmission SIGUSR1/SIGUSR2, 8 signals/byte, LSB first Same
End of message Client appends a trailing \n, sent like any other byte Client appends \n and a \0 byte; the server specifically recognizes \0 as "message finished"
Acknowledgment None — client sends and exits without confirmation Once the server sees the terminating \0, it sends SIGUSR1 back to the client to confirm full receipt
PID handshake Not needed (no ack) Before the message, the client sends its own PID as 32 signals (LSB first) so the server knows where to send the acknowledgment
Delay between signals usleep(125) usleep(150)
PID / argument validation Numeric PID required; existence checked via kill(pid, 0) Same

Neither version does per-character flow control — both rely on a fixed usleep delay to avoid overwhelming the signal queue. The bonus only adds a single end-to-end acknowledgment, not per-byte confirmation.

Build

make          # mandatory: builds "server" and "client"
make bonus    # bonus: builds "server_bonus" and "client_bonus"
make clean   # remove object files
make fclean  # remove object files and all four binaries
make re      # fclean + all

Usage

Terminal 1 — start the server:

./server
Server PID: 12345

Terminal 2 — send a message:

./client 12345 "Hello, world!"

The message shows up on the server's terminal as it's received.

Bonus — same idea, with a delivery confirmation:

./server_bonus
./client_bonus 12345 "Hello, world!"
Message is complated

(that's the exact string the program prints on acknowledgment, typo and all)

Error handling

  • client / client_bonus refuse a non-numeric PID, reject a PID that doesn't correspond to a running process (kill(pid, 0) check), and print Connection lost. if the server process disappears mid-transmission.
  • server / server_bonus refuse to start if given any command-line arguments — they only accept ./server / ./server_bonus with nothing after it.

Project structure

.
├── Makefile
├── server.c          # Mandatory server
├── client.c           # Mandatory client
├── server_bonus.c       # Bonus server — adds the end-of-message acknowledgment
└── client_bonus.c        # Bonus client — sends its PID first, waits for the ack

License

MIT — see LICENSE.

About

Two programs, server and client, that message using UNIX signals

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages