- Introduction
- Features
- Technologies
- Architecture
- Prerequisites
- Installation
- Configuration
- Usage
- Message Protocol
- Contributing
- License
- Contact
- Acknowledgements
Welcome to the PyQt5 Chat Application with Exclusive Voice, a real-time chat platform that seamlessly integrates both text and voice communication. This application ensures that only one user can speak at a time, preventing overlapping audio and fostering organized conversations. Built with Python's PyQt5 for the client and leveraging socket programming for the server, this project offers a robust solution for real-time interactions.
- User Authentication: Securely log in using unique nicknames.
- Real-time Text Chat: Instant messaging with all connected users.
- Exclusive Voice Communication: Only one user can speak at a time, preventing audio overlap.
- Online Users List: View currently connected users with active voice indicators.
- Responsive GUI: User-friendly interface built with PyQt5.
- Error Handling: Graceful handling of connection issues and other errors.
- Voice Transmission: Real-time voice data transmission using
PyAudio
. - Threaded Server: Efficiently manages multiple clients using Python's threading.
- Framework: PyQt5
- Audio Handling: PyAudio
- Networking: Socket Programming
- Threading: Python's
threading
module
- Runtime: Python 3.x
- Networking: Socket Programming
- Threading: Python's
threading
module - Data Handling: Base64 Encoding/Decoding for audio data
The application follows a Client-Server architecture:
- Client: Built with PyQt5, the client handles the user interface, capturing audio input, displaying messages, and managing user interactions.
- Server: Manages multiple client connections, relays messages and audio data between clients, and ensures that only one user can transmit voice at a time.
- Python 3.6 or higher
- pip (Python package installer)
- Git (for cloning the repository)
- PyQt5: For the client GUI
- PyAudio: For audio handling in the client
- Other Python Packages: As specified in
requirements.txt
for both server and client
git clone https://github.com/freeb5d/chatroom.git
cd chatroom
-
Navigate to the
server
Directory:cd server
-
Create a Virtual Environment (Optional but Recommended):
python3 -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install Dependencies:
pip install -r requirements.txt
-
Configure Server Settings:
- Open
server.py
and ensure theHOST
andPORT
variables are set correctly. By default, it useslocalhost
. - Alternatively, you can use environment variables or a
config.py
file for configuration.
- Open
-
Open a New Terminal and Navigate to the
client
Directory:cd client
-
Create a Virtual Environment (Optional but Recommended):
python3 -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install Dependencies:
pip install -r requirements.txt
-
Configure Client Settings:
- Open
client.py
and ensure theSERVER_HOST
andSERVER_PORT
variables match the server's IP address and port. By default, it useslocalhost
. - You can also set these via environment variables or a configuration file.
- Open
HOST = 'localhost' # Server's IP address
PORT = 5050 # Port number
# Server configuration
SERVER_HOST = 'localhost' # Update to server's IP if accessing remotely
SERVER_PORT = 5050 # Port number
Note: Ensure that the server's IP address and port are correctly configured in both the server and client. If accessing the server remotely, replace 'localhost'
with the server's public IP address in the client configuration.
-
Ensure You Are in the
server
Directory and the Virtual Environment is Activated. -
Start the Server:
python server.py
- The server will start and listen for incoming client connections on the specified
HOST
andPORT
. - You should see output indicating that the server has started, e.g.,
Chat server started on localhost:5050
.
- The server will start and listen for incoming client connections on the specified
-
Ensure You Are in the
client
Directory and the Virtual Environment is Activated. -
Start the Client Application:
python client.py
- A PyQt5 GUI window will appear.
- Enter a unique nickname in the provided input field.
- Click the Connect button to establish a connection with the server.
While this application uses socket programming for real-time communication, here's an overview of the key message protocols used between the client and server:
Message Type | Format | Description |
---|---|---|
User Registration | <nickname>\n |
Sent by the client immediately after connecting to register a unique nickname. |
User List Update | USERLIST:<user1>,<user2>,...\n |
Sent by the server to update the list of online users. |
Status Update | STATUS:<START/STOP>:<nickname>\n |
Indicates a user has started or stopped talking. |
Text Message | MSG:<message>\n |
Sent by the client to broadcast a text message. |
Voice Data | VOICE:<base64_encoded_audio>\n |
Sent by the client to transmit voice data. |
Server Message | SERVER:<message>\n |
General messages from the server (e.g., user joined). |
Busy Status | STATUS:BUSY\n |
Sent by the server to a client if someone else is currently talking. |
Contributions are welcome! To ensure a smooth collaboration, please follow these steps:
-
Fork the Repository
-
Create a Feature Branch
git checkout -b feature/YourFeature
-
Commit Your Changes
git commit -m "Add some feature"
-
Push to the Branch
git push origin feature/YourFeature
-
Open a Pull Request
Please ensure your code adheres to the project's coding standards and includes appropriate tests.
This project is licensed under the MIT License.
-
Author: kaveh T
-
GitHub: freeb5d