Screen.Recording.2026-05-25.at.7.41.32.PM.mov
This is a learning project for socket programming in C++.
References used:
- Beej’s Guide to Network Programming
- https://www.learncpp.com/
The project is a simple chat application where users can:
- connect to a server.
- create chats.
- join existing chats.
- and exchange messages in real time.
I implemented two server approaches:
-
Thread-pool server (
servert)- Uses a thread pool to process client tasks concurrently.
-
poll()event-driven server (serverp)- Uses
poll()to handle multiple clients in a single event loop. - Better suited for scalable I/O handling.
- Supports broadcasting updates (for example, chat list updates and message updates).
- Uses
The client is multithreaded:
- one thread reads user input.
- one thread listens for server updates.
This allows the client to keep chat state updated in real time while the user is typing.
Communication uses a simple custom TCP protocol framed by a 4-byte length header (handled by Utils::sendAll / Utils::receiveAll).
- List chats:
GET /chats
- Get one chat (messages):
GET /chat/<chat_name>
- Create chat:
POST /chat/<chat_name>
- Send message:
POST /message/<chat_name>/username:<username>{<message>}
Common response patterns:
- Chat list:
/chats/followed by one chat name per line
- Single chat content:
/chat/<chat_name>followed by one message per line
- Errors / status:
Chat not foundChat already existsInvalid requestOK
- The protocol is intentionally lightweight for learning purposes.
- Request parsing currently expects valid formats (especially for
POST /message).
makeThread-pool server:
./servertpoll() server:
./serverp./clientYou can run multiple client instances to simulate multiple connected users.