Skip to content

Chanchal70021/multithreaded-chat-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 

Repository files navigation

Multithreaded C++ Chat Server

A high-performance, feature-rich multithreaded chat server implemented in modern C++ using epoll, sockets, threads, and synchronization primitives. Supports multiple rooms, user authentication, colored output, and administrative commands.


πŸš€ Features

  • βœ… Multithreaded server using std::thread
  • βœ… Epoll-based I/O multiplexing for efficient socket management
  • βœ… Room-based chat (join, create, leave rooms)
  • βœ… User registration and login with basic auth
  • βœ… Admin controls: kick users, private rooms
  • βœ… Colored messages: SYSTEM, PRIVATE, USER
  • βœ… Thread-safe logging with timestamps
  • βœ… Server statistics: uptime, total connections, messages
  • βœ… Graceful shutdown (Ctrl+C)

🧱 Project Structure

chat-server/
β”œβ”€β”€ Client.cpp           # Complete chat server logic
β”œβ”€β”€ Server.cpp           # Optional extended version with CLI args and monitoring
β”œβ”€β”€ README.md            # Project documentation

πŸ› οΈ Build Instructions

Prerequisites

  • g++ (C++17+)
  • Linux (epoll is Linux-specific)

Build

g++ Client.cpp -o chat_server -pthread

Or if you're using the advanced version:

g++ Server.cpp -o chat_server -pthread

πŸ§ͺ Run the Server

./chat_server [port]

Default port: 8888

Example:

./chat_server 8888

πŸ–₯️ Connect a Client

Use telnet or nc (netcat):

telnet 127.0.0.1 8888

πŸ’¬ Command List

  • /login <user> <pass> – Log in
  • /register <user> <pass> – Register
  • /join <room> [pass] – Join room
  • /create <room> [pass] – Create new room
  • /list – List rooms
  • /who – See members in current room
  • /msg <user> <msg> – Private message
  • /kick <user> – Kick user (admin only)
  • /stats – Server stats
  • /quit – Disconnect

🎨 Message Types

  • SYSTEM: Yellow
  • PRIVATE: Magenta
  • USER: Cyan timestamp + green username

πŸ“‚ Logs

  • Stored in chat_server.log
  • Timestamped and thread-safe

🧩 Advanced CLI Options (Server.cpp only)

./chat_server -p <port> -l <log_file> -v

Flags:

  • -p / --port: Set port
  • -l / --log: Set log file path
  • -v / --verbose: Enable verbose logging

πŸ“Š Example Output

[12:01:01] [SYSTEM] User Darelene joined the room
[12:01:02] Darelene: Hello everyone!
[12:01:05] [PRIVATE] Admin: Please check your DM

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages