Multi-threaded chat client with socket programming
Advanced C++ networking project for educational purposes
A comprehensive educational resource for learning C++ network programming, featuring real-time messaging, multi-threading, and secure communication.
Instant message delivery with TCP/IP protocol and non-blocking sockets.
Secure login system with session management and username validation.
Message encryption using session keys and cryptographic functions.
TCP/IP networking with Winsock2 and POSIX socket support.
Concurrent operations with thread-safe message handling.
Scalable server supporting 100+ concurrent clients.
# Using build script (recommended)
scripts\build.bat
# Using CMake
mkdir build
cd build
cmake ..
cmake --build .
# Using build script
chmod +x scripts/build.sh
./scripts/build.sh
# Using CMake
mkdir build
cd build
cmake ..
make
# Install dependencies
brew install openssl cmake
# Build project
chmod +x scripts/build.sh
./scripts/build.sh
./bin/chat_server
# Enter port (default: 54000)
# Server starts listening...
./bin/chat_client
# Enter server IP (127.0.0.1)
# Enter port (54000)
# Enter username and password
/help - Show commands/quit - Exit client/private user msg - Send private message/history - Show message history/stats - Show statistics/kick user - Kick user/broadcast msg - Broadcast message/quit - Stop serverclass ChatClient {
bool initialize();
bool start(serverIP, port);
void stop();
void run();
void sendMessage(content);
void sendPrivateMessage(user, msg);
};
class ChatServer {
bool initialize(port);
bool start();
void stop();
void run();
int getClientCount();
void kickClient(username);
};
Thread-safe priority queue with advanced routing capabilities:
MessageQueue queue(1000);
queue.push(message);
QueueMessage msg = queue.pop();
Comprehensive security features for safe communication:
std::string encrypted = xorEncrypt(message, key);
std::string decrypted = xorDecrypt(encrypted, key);
Comprehensive utility library with 50+ functions:
Advanced threading model for optimal performance:
The project includes 50+ configurable settings:
server.port - Server port (default: 54000)server.max_clients - Maximum clients (100)server.timeout - Connection timeout (300s)server.buffer_size - Buffer size (4096 bytes)server.enable_logging - Enable loggingclient.server_ip - Server IP (127.0.0.1)client.server_port - Server port (54000)client.reconnect_attempts - Reconnect tries (3)client.buffer_size - Buffer size (4096)client.enable_logging - Enable loggingsecurity.enable_encryption - Enable encryptionsecurity.encryption_algorithm - Algorithm (XOR)security.session_key_length - Key length (32)security.enable_authentication - Auth requiredperformance.thread_pool_size - Thread pool (4)performance.queue_size - Queue size (1000)performance.flush_interval - Flush interval (1000ms)performance.enable_batching - Enable batchingPerfect for learning advanced C++ concepts:
Ideal for various learning levels:
// Initialize client
ChatClient client;
client.initialize();
// Connect to server
client.start("127.0.0.1", 54000);
// Send messages
client.sendBroadcast("Hello World!");
client.sendPrivateMessage("user", "Private msg");
// Run client loop
client.run();
// Initialize server
ChatServer server;
server.initialize(54000);
// Start server
server.start();
// Get statistics
int clients = server.getConnectedClientsCount();
auto users = server.getOnlineUsers();
// Run server loop
server.run();
// String utilities
auto parts = StringUtils::split("a,b,c", ',');
auto joined = StringUtils::join(parts, "-");
// Time utilities
auto timestamp = TimeUtils::getCurrentTimestamp();
// Crypto utilities
auto encrypted = CryptoUtils::xorEncrypt(msg, key);
// Logging
Logger::info("Application started", "Main");
// Create queue manager
auto queueManager = std::make_shared<MessageQueueManager>();
auto queue = queueManager->getQueue("test", 1000);
// Add messages
QueueMessage msg("Hello", "user", "", 5);
queue->push(msg);
// Process messages
QueueMessage received = queue->pop();
Solutions:
Solutions:
netstat -tulpn | grep 54000kill -9 <PID>./chat_server --port 54001Solutions:
sudo apt-get install build-essentialxcode-select --installSolutions:
sudo apt-get install libssl-devsudo yum install openssl-develbrew install opensslSolutions:
Solutions:
For security vulnerabilities, please email directly:
This project is licensed under the MIT License for educational purposes.
MIT License
Copyright (c) 2026 RSK World
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
When using this project, please provide proper attribution:
Molla Samser
Founder, RSK World
Lead Developer & Architecture
Rima Khatun
Designer & Tester
Quality Assurance
Website:
https://rskworld.in
Phone:
+91 93305 39277
Address:
Nutanhat, Mongolkote
Purba Burdwan, West Bengal
India, 713147