Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MiniServ - The simplest solution

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.

Requirements

  • Linux (the program only builds/runs correctly on Linux; see the Docker note below if you're not on Linux)
  • cc (gcc/clang) and make
  • nc (netcat) for manual testing

Compilation

make

This 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

Usage

start the server

./mini_serv <port>

Example:

./mini_serv 8081
  • No argument → prints Wrong number of arguments to stderr, exits 1
  • Any fatal system/allocation error before the server starts accepting → prints Fatal error to stderr, exits 1

clients connect and interact

Open one terminal per client and connect with nc (no data argument, so the connection stays open):

nc 127.0.0.1 8081

Type a message and press Enter to broadcast it to the other connected clients. Press Ctrl+C to disconnect that client.

Running on macOS / Windows (Docker alternative)

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.

Notes

Thanks to abenamar for a working solution that guided the development of this project.

About

Rank 6 exam at 42: create a mini server in C using web sockets. One of the simplest solutions you will find. LOC: 147 (real lines)

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages