A simple multi-client chat room application implemented in C++ using Winsock for Windows. The project consists of a server and a client, allowing multiple users to connect, broadcast messages, and send private messages.
- Multi-client support (each client handled in a separate thread)
- Username registration
- Public (broadcast) messaging
- Private messaging using
@usernamesyntax - Graceful client disconnect handling
server.cpp: The chat server. Handles multiple clients, message broadcasting, and private messaging.client.cpp: The chat client. Connects to the server, sends/receives messages, and supports username input.
- Windows OS
- C++ compiler (e.g., MSVC, MinGW)
- Winsock2 library (included with most Windows C++ toolchains)
- Create a new empty C++ project.
- Add
server.cppand/orclient.cppto the project. - Build the project (Winsock2 is linked via
#pragma comment(lib, "ws2_32.lib")).
g++ server.cpp -o server.exe -lws2_32
g++ client.cpp -o client.exe -lws2_32Run the server on your machine:
./server.exeThe server listens on port 12345 by default.
Run one or more clients (on the same or different machines, if networked):
./client.exe- Enter your username when prompted.
- Type messages and press Enter to send.
- To send a private message:
@username your message - To quit: type
/quit
[alice]: Hello everyone!
[bob]: Hi Alice!
@alice Hi Alice, this is a private message.
- The server must be started before any clients connect.
- The default server address is
127.0.0.1(localhost). To connect over a network, modify the IP inclient.cpp. - Only basic error handling is implemented.
This project is provided for educational purposes.