This project is a real-time chat application where users can send and receive messages over a network. It demonstrates key C++ features such as networking (TCP/IP), multithreading, and STL. Optionally, it can include SQL integration for storing chat history in a Microsoft SQL Server database.
-
Client-Server Architecture:
- The server handles multiple clients concurrently using multithreading.
- Clients connect to the server via TCP/IP sockets.
-
Message Broadcasting:
- Messages sent by one client are broadcast to all connected clients in real time.
-
STL Usage:
- Use
std::vector
orstd::unordered_map
to manage connected clients. - Use
std::thread
andstd::mutex
for thread-safe operations.
- Use
-
Optional SQL Integration:
- Store chat messages in a Microsoft SQL Server database for persistence.
- Allow users to retrieve past messages from the database.
-
Error Handling:
- Handle disconnections gracefully.
- Ensure thread safety when accessing shared resources.
RealTimeChat/
├── include/
│ ├── Client.hpp // Client class definition
│ ├── Server.hpp // Server class definition
│ ├── Message.hpp // Message struct definition
│ └── Database.hpp // Optional: SQL database wrapper
├── src/
│ ├── Client.cpp
│ ├── Server.cpp
│ ├── Message.cpp
│ └── Database.cpp // Optional: SQL implementation
├── main.cpp // Main entry point
├── CMakeLists.txt // Build configuration
└── README.md // Project documentation
-
Server:
- Listens for incoming client connections.
- Maintains a list of connected clients.
- Broadcasts messages received from one client to all other clients.
-
Client:
- Connects to the server via TCP/IP.
- Sends messages to the server and displays messages received from other clients.
-
Database (Optional):
- Stores chat messages in a table (
Messages
) with columns:Timestamp
,Sender
,Message
. - Allows users to query past messages.
- Stores chat messages in a table (
- STL:
std::vector
,std::unordered_map
,std::thread
,std::mutex
. - OOP: Encapsulation and modularity in designing
Client
,Server
, andDatabase
classes. - Multithreading: Concurrent handling of multiple clients using threads.
- Networking: TCP/IP sockets for client-server communication.
- SQL: Interaction with Microsoft SQL Server using ODBC (optional).
- A user starts the server application.
- Multiple clients connect to the server and join the chat room.
- When a client sends a message, the server broadcasts it to all connected clients.
- Optionally, the server stores the message in a database for later retrieval.