A lightweight multi-client TCP chat application built from scratch in C, using raw BSD sockets and POSIX threads (pthreads). It demonstrates low-level network programming concepts including socket creation, binding, listening, accepting connections, and concurrent client handling.
- TCP server that accepts multiple simultaneous client connections
- Thread-per-client architecture: each connected client is handled on its own detached pthread
- TCP client with a simple CLI: type a message and hit Enter to broadcast it
- Basic message framing over the TCP stream
- The server creates a listening socket and spawns a dedicated thread to accept incoming connections.
- Each accepted connection is handed off to its own thread, which listens for incoming data and prints it.
- Clients connect via
connect(), send their username once, then stream chat messages line by line.
- Language: C
- Networking: POSIX sockets (
socket,bind,listen,accept,connect,send,recv) - Concurrency: POSIX threads (
pthread_create,pthread_detach)
# Server
gcc SocketServer.c -o SocketServer -lpthread
./SocketServer
# Client
gcc Client.c -o Client -lpthread
./Client- Broadcast messages to all connected clients (currently server-side only)
- Migrate from thread-per-client to
select()/poll()for scalability - Message framing/delimiting for reliable parsing over TCP streams
- IPv6 support
Built as part of a self-taught journey into systems & network programming in C.