Opticom is a high-performance, multi-client chat server built in C++ using low-latency and fast-optimized methods. This project was developed as part of the IT-227 Computer System Programming Course in the B.Tech ICT Branch.
- Multi-client support: Handle multiple clients simultaneously using threading
- Real-time messaging: Broadcast messages to all connected clients
- Thread-safe: Uses mutex locks for safe concurrent access
- Cross-platform: Works on Linux, macOS, and other Unix-like systems
- Signal handling: Graceful shutdown with Ctrl+C
- Configurable port: Run on any available port
- Enhanced client UI: Colorful terminal interface with better message formatting
- Message Encryption: XOR-based encryption for secure communication between clients and server
- User Blocking: Block/unblock users to prevent receiving messages from them
- Privacy Protection: Blocked users cannot send private messages to you
- Rooms: Create and join different chat rooms
- Private Messages: Send direct messages to specific users
- Message History: Persistent chat history per room saved to files
- Pinned Messages: Pin important messages to room boards
- Rate Limiting: Built-in spam protection (3 messages per second)
- Room Slowmode: Admin-controlled message cooldown per room
- User List: View online users and their current rooms
- Admin Console: Built-in server console with commands
- User Management: Kick users, broadcast server messages
- Room Management: Set slowmode for specific rooms so spam does not happen.
- Colorful Logging: Server console displays colored logs for easy monitoring
The server uses:
- TCP sockets for reliable communication
- POSIX threads for handling multiple clients
- Mutex locks for thread-safe client management
- Signal handling for graceful shutdown
- C++11 compatible compiler (g++, clang++)
- POSIX-compliant system (Linux, macOS, etc.)
- Make utility
# Build both server and client
make
# Or build individually
make opticom # Server only
make client # Client only
# Debug build
make debug
# Clean build artifacts
make clean# Run on default port (8080)
./opticom
# Run on custom port
./opticom 9090
# Or using make
make run
make run-port PORT=9090# Connect to localhost on default port
./client
# Connect to specific server and port
./client 192.168.1.100 8080
# Or using make
make run-client
make run-client IP=192.168.1.100 PORT=8080- Start the server:
./opticom - Open multiple terminal windows
- Run clients in each terminal:
./client - Type messages in any client β they will be broadcast to all others
# Terminal 1: Start server
./opticom
# Terminal 2: Connect as Alice
./client 8080
# Enter username: Alice
# Type: Hello everyone!
# Terminal 3: Connect as Bob
./client 8080
# Enter username: Bob
# You'll see: [12:34:56] Alice: Hello everyone!
# Type: Hi Alice!# Block a user
/block SpamBot
# Check your block list
/blocklist
# Unblock later
/unblock SpamBot
# All messages are automatically encrypted in transit# Join a room
/join gaming
# Pin a message
/pin Check out the new update!
# View pinned messages
/pins
# List all rooms
/rooms/help- Show all available commands/list- List all online users and their rooms/rooms- Show all active rooms with user counts/quit- Disconnect from the server
/join <room>- Join or create a room (e.g.,/join gaming)/pin <message>- Pin a message to the current room's board/pins- View all pinned messages for the current room/unpin <index>- Remove a pinned message by its number
/pm <username> <message>- Send a private message (e.g.,/pm Alice Hello!)message- Just type normally to send to your current room
/block <username>- Block messages from a user/unblock <username>- Unblock a previously blocked user/blocklist- Show your list of blocked users
/clear- Clear the client screen (local only)
While the server is running, you can type these commands in the server console:
list- Show all connected users with their IPs and roomskick <username>- Disconnect and kick a usersay <message>- Broadcast a message to all users in general roomslowmode <room> <seconds>- Set slowmode for a room (e.g.,slowmode general 10)help- Show admin commands
All messages sent between clients and the server are encrypted using XOR-based encryption. This provides:
- Basic protection against casual packet sniffing
- Obfuscation of message content in transit
- Shared key encryption for simplicity
Note: This is a simple encryption scheme suitable for educational purposes. For production use, consider implementing TLS/SSL for stronger security.
The blocking system allows you to:
- Block users who are bothering you
- Prevent blocked users from sending you messages
- Block private messages from blocked users
- View and manage your block list
How it works:
- Use
/block <username>to block someone - Blocked users' messages won't appear in your chat
- They cannot send you private messages
- Use
/unblock <username>to unblock them - Use
/blocklistto see who you've blocked
The client features a colorful, modern terminal UI with:
- Color-coded messages: Different colors for system messages, PMs, errors
- Visual indicators: Icons for joins (β), leaves (β), PMs (β), warnings (β )
- Better formatting: Clean message bubbles and organized display
- Encrypted badge: Displays encryption status in banner
The server console includes:
- Startup banner: Beautiful ASCII art banner on server start
- Colorful logs:
- π¬ Blue for chat messages
- β Green for user joins
- β Red for user disconnects
- β Yellow/red for warnings and errors
- Formatted boxes: Clean boxes for user lists and help commands
Opticom/
βββ opticom.cpp # Main server implementation
βββ client.cpp # Enhanced client with encryption and UI
βββ Makefile # Build configuration
βββ README.md # This file
βββ LICENSE # License file
βββ history/ # Auto-generated directory for chat logs
βββ history_<room>.txt # Chat history per room
βββ pins_<room>.txt # Pinned messages per room
- ChatServer class: Main server implementation
- Socket management: TCP socket creation and binding
- Client handling: Thread-per-client architecture
- Message broadcasting: Send messages to all connected clients with blocking support
- Client management: Add/remove clients safely
- Encryption module: XOR-based encryption for all messages
- Blocking system: Per-user block lists stored in client info
- Room management: Support for multiple chat rooms with history
- Rate limiting: Per-client message rate tracking
- Enhanced client: Modern terminal UI with colors and formatting
- Connection management: Connect to server and maintain connection
- Message handling: Encrypt/decrypt messages automatically
- Threading: Separate thread for receiving messages
- UI formatting: Color-coded messages based on type and content
- Local commands:
/clearfor screen management
- Encryption: XOR-based encryption with shared key
- All messages encrypted before transmission
- Automatic decryption on reception
- Symmetric key encryption (encrypt = decrypt for XOR)
- Blocking: Server-side filtering
- Block list stored per client
- Filtered during broadcast and private messages
- Prevents blocked users from contacting you
- Uses
std::mutexto protect shared client list lock_guardfor automatic mutex management- Thread-safe client addition/removal
- Safe access to block lists during message broadcasting
# Install to system
make install
# Uninstall
make uninstallThe server handles SIGINT (Ctrl+C) and SIGTERM signals for graceful shutdown:
- Closes all client connections
- Cleans up resources
- Exits cleanly
- Socket creation and binding errors
- Client connection failures
- Message sending failures
- Graceful client disconnection handling
- Efficient message broadcasting with filtering
- Minimal memory allocation
- Thread-per-client model for simplicity
- Encryption overhead is minimal (XOR operations)
- Block list checks are O(n) but efficient for typical use
- Message history saved asynchronously to disk
Opticom is designed for Unix-like systems (Linux, macOS). If you're on Windows, you can still build, run, and test it easily using one of the following methods.
-
Install Visual Studio Code and the Remote - SSH extension (blue
><icon). -
Set up a Linux VM (Ubuntu recommended) in VirtualBox or VMware Workstation Player.
-
Inside the VM:
sudo apt update sudo apt install openssh-server -y sudo systemctl enable ssh sudo systemctl start ssh -
Find your VMβs IP:
ip a
Look for a line like
inet 192.168.x.xundereth0. -
On Windows, open VS Code β Ctrl + Shift + P β Remote-SSH: Connect to Host...
ssh username@192.168.x.x -
Once connected, open the Opticom folder and build normally:
make ./opticom 8080 ./client localhost 8080
-
Enable WSL and install Ubuntu:
wsl --install -
Launch Ubuntu:
sudo apt update sudo apt install g++ make -y
-
Clone and build:
git clone https://github.com/vaishcodescape/Opticom.git cd Opticom make ./opticom ./client -
WSL behaves like native Linux β no VM setup required.
You can compile directly on Windows with MinGW or Cygwin, but youβll need to:
- Replace Unix headers (
sys/socket.h,netinet/in.h, etc.) with Windows equivalents (winsock2.h,ws2tcpip.h). - Initialize Winsock with
WSAStartup(). However, using a Unix environment (VM or WSL) is strongly recommended.
See MIT LICENSE file for details.
This project was developed as part of IT-227 Computer System Programming Course in the B.Tech ICT Branch, focusing on:
- Socket programming
- Multi-threading
- System programming concepts
- Network communication protocols