A robust, multi-threaded client-server chat application built using Python. Originally a simple CLI tool, this project has been upgraded to feature a modern graphical user interface (GUI), secure user authentication, and a custom JSON-based TCP networking protocol.
- Graphical User Interface: A clean, dark-themed UI built with PyQt6, featuring separate tabs for different conversations.
- Secure Authentication: User registration and login functionality backed by a local SQLite database and bcrypt password hashing.
- Group & Private Messaging: Support for global channels (e.g.,
#General,#Coders,#Gamers) as well as one-on-one direct messaging (DMs). - Real-Time Online Roster: A live-updating sidebar displaying currently connected users.
- Robust TCP Networking: Custom buffer management using newline-delimited JSON to safely handle fragmented or "sticky" network packets.
- Multi-Threading: Allows the server to handle multiple clients concurrently without blocking.
- Python 3.12 or 3.13 (Note: Python 3.14+ may require manual C++ compilation for the PyQt6 library, so 3.12/3.13 is highly recommended).
It is recommended to use a virtual environment to install the dependencies (PyQt6 and bcrypt).
-
Create a virtual environment:
python -m venv .venv
(Windows users can also use the launcher:
py -3.13 -m venv .venv) -
Activate the virtual environment:
-
Windows:
.venv\Scripts\activate
-
macOS/Linux:
source .venv/bin/activate
-
-
Install the required libraries:
pip install -r requirements.txt
-
Start the Server: Open a terminal, activate your virtual environment, and run the server. (On the first run, it will automatically generate the
chat_users.dbdatabase).python server.py
You should see a message indicating the server is listening on 0.0.0.0:65432.
-
Start the Client: Open a separate terminal window, activate the virtual environment, and launch the GUI client:
python gui_client.py
-
Connect and Authenticate:
- In the client window, enter
127.0.0.1and click Connect. - The server will prompt you in the chat box to type
1to Login or2to Register. Type your response directly into the message input field and press Send.
- In the client window, enter
- Start the Server:
Run
server.pyon your host machine. Make sure the host IP in the script is set to0.0.0.0to accept external connections. - Start the Client:
On a different machine on the same network, open
gui_client.py. - Connect:
Instead of
127.0.0.1, enter the local IPv4 address of the host machine (found usingipconfigon Windows orifconfigon macOS/Linux).
If you do not want to set up Python, you can use the standalone executables:
- Navigate to the
dist/folder. - Run
server.exeon the host machine. - Distribute and run
ChatClient.exeon client machines, entering the host's IPv4 address to connect.
server.py- Central server handling connections, routing, and user sessions.gui_client.py- Main application executable containing the PyQt6 interface.client_core.py- Networking backend handling socket transmission and buffering.db_manager.py- Database handler forchat_users.dband credential verification.requirements.txt- Project dependencies.
- Language: Python 3
- Libraries:
socket,threading,json,sqlite3(Standard),PyQt6,bcrypt(Third-party) - Protocol: TCP/IP