A multi-threaded, client-server chat system built from scratch in C++ using TCP/IP sockets. It's designed to handle multiple concurrent users for real-time messaging, showcasing fundamental low-level network programming and concurrency concepts.
- Multi-Threaded Server: Utilizes a thread-per-client model to handle multiple concurrent users in parallel.
- Real-time Messaging: Supports both public broadcast messages and private one-to-one messages.
- User Nicknames: Allows users to set and change their nicknames with the
/nickcommand. - Online User List: Users can request a list of all currently connected clients with the
/listcommand. - Graceful Shutdown: The server can be shut down cleanly using a
SHUTDOWNcommand in its console, notifying all clients. - External Configuration: The server port is configured via an external
server.conffile, so no recompilation is needed to change it. - Asynchronous Client: The client uses
select()to handle both user input and network messages simultaneously, ensuring notifications are never missed. - Object-Oriented Design: The server code is refactored into a clean, encapsulated
Serverclass.
- A C++ compiler that supports C++17 (e.g.,
g++orclang++) make
- Clone the repository:
git clone https://github.com/Angad8285/cpp-chat-system
- Navigate to the project directory:
cd cpp-chat-system - Compile the project:
This will create two executables in your root directory:
make
serverandclient.
You will need at least two separate terminal windows.
-
Start the Server: In your first terminal, run the server executable:
./server
The server will start and listen on the port specified in
server.conf(default is 8080). -
Start the Client(s): In one or more other terminals, run the client executable:
./client
The client will connect to the server. You can now start chatting!
-
Server Administration:
- To change the port, edit the
PORTvalue in theserver.conffile and restart the server. - To shut down the server gracefully, type
SHUTDOWNin the server's terminal window and press Enter.
- To change the port, edit the
Once connected, you can type messages to send them publicly. The following special commands are available:
/nick <new_name>- Changes your nickname.- Example:
/nick Alice
- Example:
/msg <username> <message>- Sends a private message to a specific user.- Example:
/msg Bob Hello there!
- Example:
/list- Shows a list of all users currently online./exit- Disconnects you from the server.