A Discord-like desktop chat application built with Python. Features a modern dark-themed GUI (CustomTkinter), user authentication, encrypted connections, multiple channels, message history, and real-time notifications.
- Discord-inspired UI — Dark theme with channel sidebar, message area, and online user list
- User Authentication — Registration and login with bcrypt-hashed passwords
- Multiple Channels — Create and switch between chat rooms with persistent message history
- Private Messaging — Direct messages between users with
/msg - TLS Encryption — Optional SSL/TLS support for secure connections
- SQLite Database — Persistent storage for users, channels, and messages
- Rate Limiting — Flood protection (5 messages/second per user)
- Input Validation — Username, password, message, and channel name validation
- Desktop Notifications — Toast notifications for messages in other channels and PMs
- Slash Commands —
/msg,/me,/quitstill work from the message input
pip install -r requirements.txtpython server.py --no-tlsUse --no-tls for local development. The server listens on 127.0.0.1:5050 by default.
python client.pyA GUI window will open. Register a new account or log in, and you're chatting!
Open multiple client windows to test multi-user chat.
The client features a three-panel layout inspired by Discord:
- Left sidebar — Channel list with a "+" button to create new channels
- Center — Message area with timestamps and a message input bar
- Right sidebar — Online user list with status indicators
python server.py [OPTIONS]
--host HOST Bind address (default: 127.0.0.1)
--port PORT Listen port (default: 5050)
--db PATH SQLite database file (default: chat_data.db)
--no-tls Disable TLS encryption (for development)
--cert FILE TLS certificate file (default: certs/server.crt)
--key FILE TLS private key file (default: certs/server.key)
To enable encrypted connections:
python certs/gen_certs.py # Generate self-signed certificates
python server.py # Start with TLS enabledThen check "Use TLS" in the client's Advanced connection settings.
Type these in the message input bar:
| Command | Description |
|---|---|
/msg <user> <message> |
Send a private message |
/me <action> |
Send an action (e.g., /me waves) |
/quit |
Disconnect and close |
python-socket-chat/
├── server.py # Server entry point
├── client.py # Client entry point (GUI)
├── requirements.txt
├── certs/
│ └── gen_certs.py # Self-signed TLS certificate generator
├── shared/
│ ├── protocol.py # Length-prefixed JSON wire protocol
│ ├── constants.py # Shared constants and message types
│ └── validators.py # Input validation and sanitization
├── server_app/
│ ├── chat_server.py # Multi-threaded chat server
│ ├── auth.py # bcrypt password hashing, session tokens
│ ├── database.py # SQLite database layer
│ ├── rate_limiter.py # Per-user rate limiting
│ └── channel_manager.py # Channel membership tracking
└── client_app/
├── network.py # Socket connection and TLS
├── session.py # Client-side session state
└── ui/
├── app.py # Main application window
├── login_screen.py # Login/registration screen
├── chat_screen.py # Chat layout (3-column grid)
├── theme.py # Discord dark theme colors and fonts
├── notifications.py # Desktop notifications
└── components/
├── sidebar_channels.py
├── message_area.py
├── sidebar_users.py
├── message_input.py
└── top_bar.py
Communication uses a length-prefixed JSON format over TCP:
[4-byte big-endian payload length][UTF-8 JSON payload]
This replaces newline-delimited text, correctly handling multiline messages and structured data.
SQLite stores four tables:
- users — Accounts with bcrypt-hashed passwords
- channels — Chat rooms with descriptions
- messages — Message history (indexed by channel and timestamp)
- sessions — Authentication tokens with expiry
- Passwords hashed with bcrypt (12 rounds)
- Session tokens generated via
secrets.token_hex(32) - Optional TLS/SSL encryption for all traffic
- Input validation on usernames, passwords, messages, and channel names
- Rate limiting prevents message flooding
- Python 3.10+
- Dependencies:
customtkinter,bcrypt,plyer,Pillow
MIT