PyChat is a lightweight desktop chat application that pairs a PySide6 client with a threaded TCP server. It gives you a small, readable Python codebase for experimenting with socket networking, JSON message payloads, client registration, and real-time message broadcasting.
- Desktop chat client: Qt-based interface built with PySide6.
- Threaded TCP server: Handles multiple connected clients concurrently.
- JSON protocol: Sends structured requests and responses over persistent socket connections.
- Client registration: Stores usernames and passwords per server before allowing messages.
- Broadcast messaging: Relays accepted chat messages to all connected clients.
- File-backed configuration: Generates editable JSON config files for client and server settings.
- Shared networking layer: Keeps socket framing, send, receive, and shutdown behavior in
network.py.
PyChat/
├── client/
│ ├── main.py # Desktop client entry point
│ ├── application.py # Wires the GUI to the client networking layer
│ ├── client.py # Client connection, registration, and messaging logic
│ ├── config/defaults.py # Default client configuration
│ └── gui/ # PySide6 windows, pages, widgets, and styles
├── server/
│ ├── main.py # Server entry point
│ ├── server.py # Server lifecycle and request handling
│ ├── const.py # Default server configuration and response constants
│ └── userInt.py # Console input/output helper for server commands
├── network.py # Shared socket client/server managers
├── jsonDB.py # JSON file persistence helper
├── pyproject.toml # Python and dependency metadata
└── poetry.lock # Locked dependency versions
- Python
>=3.14,<3.15 - Poetry 2.x or newer
- A network interface and port you can bind for the server
PyChat currently depends on:
pyside6 = ">=6.11.1,<7.0.0"Clone the repository and install the locked dependencies with Poetry:
git clone https://github.com/kavinappsri/PyChat---Messaging-App.git
cd PyChat
poetry installIf you prefer to use an existing virtual environment, install the project dependency directly:
python3.14 -m pip install "pyside6>=6.11.1,<7.0.0"PyChat creates JSON configuration files automatically the first time each entry point runs.
Run the server once to generate server/serverconfig.json:
poetry run python -m server.mainStop it by typing the configured stop word, which is stop by default. Then edit the generated file as needed:
{
"ip": "0.0.0.0",
"port": 8080,
"stopWord": "stop",
"serverName": "Server1234",
"registeredClients": {}
}Run the client once to generate client/config.json:
poetry run python -m client.mainClose the app, then edit the generated username and password before connecting to a shared server:
{
"encoding": "utf-8",
"username": "Guest",
"password": "hello_world",
"servers": {}
}Using unique credentials per user is recommended because the server registers usernames and rejects duplicate or mismatched credentials.
Start the server in one terminal:
poetry run python -m server.mainStart one or more clients in separate terminals:
poetry run python -m client.mainIn the client window:
- Enter the server IP address.
- Enter the server port, such as
8080. - Select Connect To Server.
- Type a message and select Send.
- Select Disconnect to leave the server.
To stop the server, type the configured stop word in the server terminal:
stop
PyChat frames each socket message with a 10-byte length header followed by a JSON payload. Clients send an action field to request server behavior.
Example registration payload:
{
"action": "register",
"username": "Guest",
"password": "hello_world"
}Example chat payload:
{
"action": "msg",
"username": "Guest",
"password": "hello_world",
"message": "Hello from PyChat!"
}Server responses include a status field:
| Status | Meaning |
|---|---|
1 |
OK |
2 |
Bad request |
3 |
Action denied |
network.pyowns socket setup, message framing, broadcast queues, and shutdown behavior.server/server.pyvalidates requests, persists registered clients, and broadcasts accepted messages.client/client.pymanages async connection setup, server registration, message sending, and receive-loop signals.client/gui/contains the PySide6 interface pages and reusable widgets.
