Skip to content

Subham-x/PyChatApp

Repository files navigation

PyChat - Multi-Channel Encrypted Chat Application

🚀 Quick Start

Option 1: Using Batch Files (Recommended)

  1. Start Server: Double-click start_server.bat
  2. Start Client: Double-click start_client.bat

Option 2: Manual Start

# Start Server
python server_multichannel.py

# Start Client (in another terminal)
python client_multichannel.py

📋 How It Works

Multi-Channel Architecture

                    ┌─────────────────┐
                    │   PyChat Server │
                    │   (Central Hub) │
                    └────────┬────────┘
                             │
        ┌────────────────────┼────────────────────┐
        │                    │                    │
   ┌────▼────┐          ┌────▼────┐         ┌────▼────┐
   │ Channel │          │ Channel │         │ Channel │
   │  "Work" │          │ "Gaming"│         │ "Family"│
   │ PIN:1111│          │ PIN:2222│         │ PIN:3333│
   └────┬────┘          └────┬────┘         └────┬────┘
        │                    │                    │
   ┌────┼────┐          ┌────┼────┐         ┌────┼────┐
   │Users (3)│          │Users (5)│         │Users (2)│
   └─────────┘          └─────────┘         └─────────┘

✨ Features

✅ Multi-Channel Support

  • Unlimited Channels: Create as many channels as needed
  • Channel Isolation: Each channel is completely isolated
  • Auto-Creation: Channels are created when first user joins
  • Auto-Cleanup: Empty channels removed after 1 minute

🔐 End-to-End Encryption

  • AES-128 Encryption: Military-grade encryption
  • PIN-Based Keys: Each channel has unique encryption key
  • Base64 Encoding: Safe message transmission

🎨 Rich Features

  • Unique Colors: Each user gets a different color
  • "You:" Prefix: Your messages show as "You:"
  • System Notifications: Colored join/leave messages
  • Real-time Updates: Instant message delivery

📖 User Guide

Connecting to a Channel

  1. Run Client

    Channel Name: Work
    Channel PIN: 1111
    Your Name: John
    
  2. If channel exists: You join existing chat

  3. If channel doesn't exist: New channel is created automatically

Channel Isolation

  • Different PINs = Different Channels
    • Channel "Work" with PIN "1111" ≠ Channel "Work" with PIN "2222"
    • Users in different channels cannot see each other's messages

Example Scenario

User A: Work + PIN 1111  →  Channel A (isolated)
User B: Work + PIN 1111  →  Channel A (same as User A)
User C: Work + PIN 2222  →  Channel B (different, isolated)
User D: Gaming + PIN 1111 → Channel C (different, isolated)

🛠️ Server Commands

While server is running, type these commands:

  • /channels - List all active channels and users
  • /stats - Show server statistics
  • /help - Show command list
  • /exit - Shutdown server gracefully

Example Output:

/channels

==================================================
Active Channels: 2
==================================================

  Channel: Work
  Users: 3
    - John
    - Alice  
    - Bob

  Channel: Gaming
  Users: 2
    - Mike
    - Sarah
==================================================

🔧 Configuration

Client Configuration

Edit client_multichannel.py:

SERVER_IP = "127.0.0.1"  # Change for LAN/Internet
PORT = 5000

Server Modes

When starting server:

  • 1. Localhost: Same PC only (127.0.0.1)
  • 2. LAN: Local network (0.0.0.0)
  • 3. Internet: Public IP (0.0.0.0 + port forward)

🌐 Network Setup

Localhost (Same PC)

  • Server: Select option 1
  • Client: Use 127.0.0.1

LAN (Same Network)

  • Server: Select option 2
  • Client: Use server's local IP (e.g., 192.168.1.100)

Internet (Public Access)

  • Server: Select option 3
  • Port Forward: Forward port 5000 to server PC
  • Client: Use server's public IP

❓ Troubleshooting

"Connection Failed" Error

Solution:

  1. Start server first: start_server.bat
  2. Check server is running
  3. Verify IP address is correct
  4. Check firewall settings

"Decryption Failed"

Cause: Wrong PIN for the channel Solution: Use the correct PIN for the channel

Colors Not Showing

Cause: Terminal doesn't support ANSI colors Solution: Use modern terminal (Windows Terminal, VS Code terminal)


📊 Architecture Evaluation

✅ Strengths (High-Scale Ready)

  1. Multi-tenancy: One server, multiple isolated channels
  2. Efficient: Thread-per-connection model
  3. Scalable: Channels created/destroyed dynamically
  4. Secure: End-to-end encryption per channel
  5. Resource-Efficient: Auto-cleanup of empty channels

⚠️ Current Limitations

  1. Threading Model: Limited to ~1000 concurrent users
  2. No Persistence: Messages not saved (memory only)
  3. Single Server: No load balancing/clustering
  4. No Authentication: Anyone with PIN can join

🚀 Production Improvements Needed

  1. Async I/O: Use asyncio for 10k+ concurrent users
  2. Database: Store messages, users, channel history
  3. Redis/Queue: Distribute load across servers
  4. WebSockets: Better for web clients
  5. User Auth: Login system with passwords
  6. Rate Limiting: Prevent spam/abuse
  7. File Sharing: Upload images/files
  8. Message History: Load previous messages

📝 Files Structure

PyChat/
├── server_multichannel.py    # Multi-channel server
├── client_multichannel.py    # Multi-channel client
├── server.py                 # Old single-channel (legacy)
├── client.py                 # Old single-channel (legacy)
├── start_server.bat          # Server launcher
├── start_client.bat          # Client launcher
├── requirements.txt          # Dependencies
└── README.md                 # This file

🎯 Use Cases

Business

  • Departments: HR, IT, Sales each have private channels
  • Projects: Each project team has dedicated channel
  • Security: PIN ensures only authorized access

Gaming

  • Guilds: Each guild has private chat
  • Teams: Coordinate without outsiders seeing
  • Tournaments: Separate channels per match

Personal

  • Family: Private family chat
  • Friends: Different friend groups
  • Study: Study groups with channel per subject

🔐 Security Notes

  • ✅ Messages encrypted end-to-end
  • ✅ PIN-based channel access
  • ✅ No plaintext transmission
  • ⚠️ PINs should be strong (not 1111, 1234)
  • ⚠️ Server operator can see plaintext (for moderation)
  • ⚠️ No TLS/SSL (add for production)

📄 License

Free to use and modify.

👨‍💻 Support

For issues or questions, check the code comments or modify as needed.


Happy Chatting! 🎉

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors