- Start Server: Double-click
start_server.bat - Start Client: Double-click
start_client.bat
# Start Server
python server_multichannel.py
# Start Client (in another terminal)
python client_multichannel.py ┌─────────────────┐
│ PyChat Server │
│ (Central Hub) │
└────────┬────────┘
│
┌────────────────────┼────────────────────┐
│ │ │
┌────▼────┐ ┌────▼────┐ ┌────▼────┐
│ Channel │ │ Channel │ │ Channel │
│ "Work" │ │ "Gaming"│ │ "Family"│
│ PIN:1111│ │ PIN:2222│ │ PIN:3333│
└────┬────┘ └────┬────┘ └────┬────┘
│ │ │
┌────┼────┐ ┌────┼────┐ ┌────┼────┐
│Users (3)│ │Users (5)│ │Users (2)│
└─────────┘ └─────────┘ └─────────┘
- 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
- AES-128 Encryption: Military-grade encryption
- PIN-Based Keys: Each channel has unique encryption key
- Base64 Encoding: Safe message transmission
- 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
-
Run Client
Channel Name: Work Channel PIN: 1111 Your Name: John -
If channel exists: You join existing chat
-
If channel doesn't exist: New channel is created automatically
- Different PINs = Different Channels
- Channel "Work" with PIN "1111" ≠ Channel "Work" with PIN "2222"
- Users in different channels cannot see each other's messages
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)
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
/channels
==================================================
Active Channels: 2
==================================================
Channel: Work
Users: 3
- John
- Alice
- Bob
Channel: Gaming
Users: 2
- Mike
- Sarah
==================================================
Edit client_multichannel.py:
SERVER_IP = "127.0.0.1" # Change for LAN/Internet
PORT = 5000When 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)
- Server: Select option 1
- Client: Use 127.0.0.1
- Server: Select option 2
- Client: Use server's local IP (e.g., 192.168.1.100)
- Server: Select option 3
- Port Forward: Forward port 5000 to server PC
- Client: Use server's public IP
Solution:
- Start server first:
start_server.bat - Check server is running
- Verify IP address is correct
- Check firewall settings
Cause: Wrong PIN for the channel Solution: Use the correct PIN for the channel
Cause: Terminal doesn't support ANSI colors Solution: Use modern terminal (Windows Terminal, VS Code terminal)
- Multi-tenancy: One server, multiple isolated channels
- Efficient: Thread-per-connection model
- Scalable: Channels created/destroyed dynamically
- Secure: End-to-end encryption per channel
- Resource-Efficient: Auto-cleanup of empty channels
- Threading Model: Limited to ~1000 concurrent users
- No Persistence: Messages not saved (memory only)
- Single Server: No load balancing/clustering
- No Authentication: Anyone with PIN can join
- Async I/O: Use
asynciofor 10k+ concurrent users - Database: Store messages, users, channel history
- Redis/Queue: Distribute load across servers
- WebSockets: Better for web clients
- User Auth: Login system with passwords
- Rate Limiting: Prevent spam/abuse
- File Sharing: Upload images/files
- Message History: Load previous messages
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
- Departments: HR, IT, Sales each have private channels
- Projects: Each project team has dedicated channel
- Security: PIN ensures only authorized access
- Guilds: Each guild has private chat
- Teams: Coordinate without outsiders seeing
- Tournaments: Separate channels per match
- Family: Private family chat
- Friends: Different friend groups
- Study: Study groups with channel per subject
- ✅ 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)
Free to use and modify.
For issues or questions, check the code comments or modify as needed.
Happy Chatting! 🎉