This project is a simple Peer-To-Peer (P2P) chat application implemented using Python. It features a client-server architecture with data compression and decompression functionalities. The application uses the observer pattern to manage the state of the connection between the client and server, and supports basic message exchange over a network.
The compression is done using Predictor algorithm (it can be referred from here and here).
The project is designed for a course named "Software Design and Development" and demonstrates principles of software design, including network communication, data compression, and design patterns.
Python 3.11 was used for the implementation.
- Client-Server Communication: Implements a basic chat system where a client can send messages to a server.
- Data Compression: Utilizes custom compression algorithms to minimize the size of transmitted data.
- Observer Pattern: Uses the observer pattern to manage connection state changes between the client and server.
- Network Handling: Includes error handling for network operations, ensuring robust communication.
- Observer: An abstract base class for implementing observers in the observer pattern.
- Observable: An abstract base class for implementing observables in the observer pattern.
- Compression: Provides functionality to compress messages before sending them over the network.
- Decompression: Handles decompression of received messages.
- Client: Connects to a server and sends messages.
- Server: Listens for incoming connections and handles received messages.
- Connection: Manages the state of the network connection between client and server.
- NetworkComponent: An abstract base class for network components.
- Node: Manages the overall chat session by setting up the client and server and managing their connection.
-
Clone the repository:
git clone https://github.com/yourusername/chat-application.git cd chat-application
-
Install dependencies: Ensure you have Python 3.x installed. Install the required packages using pip:
pip install -r requirements.txt
-
Prepare the Configuration File: Create a JSON file, e.g
config.json
with the following structure:{ "address": "127.0.0.1", "port": 5000, "peer_address": "127.0.0.1", "peer_port": 5001 }
The
address
andpeer_address
keys are optional and can be ommited, when the application runs in localhost. -
Run the Node:
py main.py config.json
observer.py
: Contains the abstract base classesObserver
andObservable
.Compression.py
: Implements data compression functionality.Decompression.py
: Implements data decompression functionality.network_component.py
: Defines theNetworkComponent
abstract base class.connection.py
: Implements theConnection
class to manage connection states.client.py
: Implements theClient
class for the client-side operations.server.py
: Implements theServer
class for the server-side operations.node.py
: Orchestrates the client-server interaction.
This project is licensed under the MIT License. See the LICENSE file for details.