A select-based, non-blocking TCP chat relay: clients connect on 127.0.0.1,
send lines of text, and the server broadcasts them to every other connected client.
Features:
- Non-blocking,
select-based I/O for handling multiple clients simultaneously - Broadcasts messages from any client to all other connected clients
- Handles client disconnections gracefully
This project is based on a school exam exercise. Exam target: Implement a mini server given the specifications and a script with useful functions (main.c). See folder given for reference, see also docs/subject-plus-notes.md for a more digestible version of the specifications.
- Linux (the program only builds/runs correctly on Linux; see the Docker note below if you're not on Linux)
cc(gcc/clang) andmakenc(netcat) for manual testing
makeThis builds mini_serv from mini_serv.c with -Wall -Wextra -Werror.
Other targets:
make clean # remove object files
make fclean # remove object files and the binary
make mem8081 # build, then run under valgrind on port 8081./mini_serv <port>Example:
./mini_serv 8081- No argument → prints
Wrong number of argumentsto stderr, exits 1 - Any fatal system/allocation error before the server starts accepting → prints
Fatal errorto stderr, exits 1
Open one terminal per client and connect with nc (no data argument, so the
connection stays open):
nc 127.0.0.1 8081Type a message and press Enter to broadcast it to the other connected clients. Press Ctrl+C to disconnect that client.
If you're not on Linux, build and run the project inside a Docker container instead. See docker-readme.md for the full build/run/exec instructions.
Thanks to abenamar for a working solution that guided the development of this project.