CadvancedbackendAI generated

Multi-threaded TCP Chat Server

A chat server that accepts multiple simultaneous client connections over TCP sockets, broadcasting messages between clients using a thread-per-connection model with pthread mutexes protecting shared client state. Learners practice POSIX sockets, pthreads, and mutex-based concurrency control in C.

Estimate
~12h
Steps
6
Completed by
0
Proposed by
codeseed.app

pthread · sys/socket.h · netinet/in.h

Project roadmap

  1. 01

    Set up the listening TCP socket

    ~1.5h

    Create, bind, and listen on a TCP socket, accepting incoming connections in a loop.

  2. 02

    Spawn a thread per client connection

    ~2h

    For each accepted connection, spawn a pthread that handles reading messages from that client.

  3. 03

    Implement thread-safe client registry

    ~2.5h

    Maintain a shared list of connected client sockets protected by a mutex, supporting add/remove.

  4. 04

    Implement message broadcasting

    ~2.5h

    When a client sends a message, iterate the client registry under lock and write it to all other sockets.

  5. 05

    Add nickname and join/leave notifications

    ~1.5h

    Let clients set a nickname on connect and broadcast join/leave/system messages.

  6. 06

    Handle disconnects and cleanup gracefully

    ~2h

    Detect closed connections, remove them from the registry, and free resources without leaking or crashing.

Ready to build this?

Get a GitHub repo and start building. Your AI reviewer checks each step as you go.

~12h · 6 steps

Tech stack

pthreadsys/socket.hnetinet/in.h