Project 2: Client-Server with Named Pipes (FIFOs)

A simple calculator server that listens on a well-known FIFO, receives requests from multiple clients, and sends responses back through client-specific FIFOs.

Quick Reference

Attribute Value
Primary Language C
Alternative Languages Rust, Python
Difficulty Level 2 (Intermediate)
Time Estimate See main guide
Knowledge Area IPC, Client-Server Architecture
Tooling None (pure syscalls)
Prerequisites See main guide

What You Will Build

A simple calculator server that listens on a well-known FIFO, receives requests from multiple clients, and sends responses back through client-specific FIFOs.

Why It Matters

This project builds core skills that appear repeatedly in real-world systems and tooling.

Core Challenges

  • Blocking behavior → open() blocks until both ends connected
  • Atomic writes → Keeping requests from multiple clients separate
  • Cleanup → Removing FIFOs on shutdown

Key Concepts

  • Map the project to core concepts before you code.

Real-World Outcome

# Terminal 1: Start server
$ ./calc_server
Server listening on /tmp/calc_server...
Received: 5 + 3 from client 12345
Sending response: 8 to /tmp/calc_client_12345
Received: 10 * 4 from client 12346
Sending response: 40 to /tmp/calc_client_12346

# Terminal 2: Client 1
$ ./calc_client "5 + 3"
Result: 8

# Terminal 3: Client 2 (simultaneously)
$ ./calc_client "10 * 4"
Result: 40

# Verify FIFOs exist
$ ls -la /tmp/calc*
prw-r--r-- 1 user user 0 Jan  1 12:00 /tmp/calc_server
prw-r--r-- 1 user user 0 Jan  1 12:00 /tmp/calc_client_12345
prw-r--r-- 1 user user 0 Jan  1 12:00 /tmp/calc_client_12346

# After clients exit, their FIFOs are cleaned up
$ ls -la /tmp/calc_client*
ls: cannot access '/tmp/calc_client*': No such file or directory

Implementation Guide

  1. Reproduce the simplest happy-path scenario.
  2. Build the smallest working version of the core feature.
  3. Add input validation and error handling.
  4. Add instrumentation/logging to confirm behavior.
  5. Refactor into clean modules with tests.

Milestones

  • Milestone 1: Minimal working program that runs end-to-end.
  • Milestone 2: Correct outputs for typical inputs.
  • Milestone 3: Robust handling of edge cases.
  • Milestone 4: Clean structure and documented usage.

Validation Checklist

  • Output matches the real-world outcome example
  • Handles invalid inputs safely
  • Provides clear errors and exit codes
  • Repeatable results across runs

References

  • Main guide: UNIX_IPC_STEVENS_VOL2_MASTERY.md
  • “The Linux Programming Interface” by Michael Kerrisk