SocketChat is a multi-client chat application implemented in C++ using POSIX sockets. It allows multiple users to join a shared chatroom, broadcast messages to all users, or send private (unicast) messages to specific users.
Built with thread support and a command-driven interface, SocketChat is designed to demonstrate real-world network programming concepts such as socket communication, concurrent handling using threads, and basic server-client architecture.
- β Multi-client support β Multiple users can join and chat simultaneously.
- β Broadcast messaging β Messages are sent to all connected users by default.
- β
Private messaging (unicast) β Send a message to a specific user using
/mesg
command. - β
List connected users β Use
/list
to see who is online, with your name highlighted. - β
Help command β
/help
shows all available commands. - β
Clean exit β
/exit
gracefully leaves the chatroom and informs others. - β Colored terminal output β Usernames, system messages, and commands are color-coded for better readability.
- β Thread-safe implementation β Uses mutexes to safely manage shared data.
Make sure you have g++
and make
installed.
make
./chat_server
By default, the server listens on port 8080.
In separate terminals (or using VSCode split terminals):
./chat_client
When you run the client, youβll be prompted to enter your name. After that, you can start chatting!
Command | Description |
---|---|
/list |
List all connected users. Your name is prefixed with > . |
/mesg NAME MSG |
Send a private (unicast) message to NAME . |
/help |
Show available commands. |
/exit |
Leave the chatroom gracefully. |
.
βββ chat_server # Compiled server executable
βββ chat_client # Compiled client executable
βββ src/
β βββ client.cpp # Client source code
β βββ server.cpp # Server source code
β βββ main.cpp # Server entry point
βββ include/
β βββ server.h # Server header
βββ .vscode/
β βββ settings.json # VSCode configuration
βββ Makefile # Build configuration
βββ README.md # Project documentation
- Language: C++ (C++11 or higher)
- Networking: POSIX sockets
- Threads: std::thread (client handler threads)
- Synchronization: std::mutex for safe client list operations
- Port: 8080 (modifiable)
- No authentication or encryption (plaintext TCP).
- Private messages are only supported via username and require users to know each other's names exactly.
- Basic error handling; production-level robustness would require more checks.
Contributions are welcome! You can:
- Submit a pull request with improvements (new features, code cleanups, etc.)
- Open an issue for bugs or suggestions
SocketChat is intended for learning and demonstration purposes. It does not implement secure communication and should not be used as-is in production environments.
If you have questions or want to share feedback, feel free to open an issue or reach out via GitHub.