Skip to content

πŸ’¬ Multi-client TCP chat server and client in C++ - supports broadcasting, private messaging, and user listing, all built with POSIX sockets and threads.

License

Notifications You must be signed in to change notification settings

Glitch-Aswin/tcp-chat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

19 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

SocketChat: A TCP-Based Multi-Client Chat Server in C++

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.


🌟 Features

  • βœ… 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.

πŸ’¬ Example Flow

image


πŸ’» Build Instructions

Make sure you have g++ and make installed.

make

▢️ Run Instructions

Start the Server

./chat_server

By default, the server listens on port 8080.

Start the Clients

In separate terminals (or using VSCode split terminals):

./chat_client

πŸ—¨οΈ Client Usage

When you run the client, you’ll be prompted to enter your name. After that, you can start chatting!

Available Commands

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.

πŸ—‚οΈ Project Structure

.
β”œβ”€β”€ 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


βš™οΈ Technical Details

  • 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)

πŸ’‘ Known Limitations

  • 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.

🀝 Contributing

Contributions are welcome! You can:

  • Submit a pull request with improvements (new features, code cleanups, etc.)
  • Open an issue for bugs or suggestions

πŸ›‘οΈ Disclaimer

SocketChat is intended for learning and demonstration purposes. It does not implement secure communication and should not be used as-is in production environments.


βœ‰οΈ Contact

If you have questions or want to share feedback, feel free to open an issue or reach out via GitHub.


About

πŸ’¬ Multi-client TCP chat server and client in C++ - supports broadcasting, private messaging, and user listing, all built with POSIX sockets and threads.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published