This project is a chat server implementation using Rust programming language, PostgreSQL database, and a broker pattern. The code is implemented based on the idea of a broker from the Async Programming in Rust book.
This project is a collaborative effort and we would like to acknowledge the contributions of:
We appreciate their hard work and dedication in making this project a success.
- Allows multiple clients to connect and communicate with each other in real-time.
- Uses a broker pattern to handle message distribution between clients.
- Messages sent by both the sender and receiver are saved in a PostgreSQL database for future reference.
- The broker is responsible for receiving and processing events from various components within the system.
- The broker maintains a HashMap named peers that keeps track of connected clients.
- The broker handles events related to inserting messages into a database.
- The broker manages client disconnections.
- The broker_loop function runs in its own asynchronous task, continuously processing events in the background.
Before running the chat server, make sure you have the following installed:
- Rust programming language: Installation Guide
- PostgreSQL database: Installation Guide
-
Clone the repository:
git clone https://github.com/YasoKarim/Chat_Server.git
-
Navigate to the project directory:
cd Chat-Server-Project
-
Install the required dependencies:
cargo build
-
Set up the PostgreSQL database:
- Create a new database in PostgreSQL for the chat server.
- Update the database connection details in the configuration file (
config.toml
) with your PostgreSQL credentials.
-
Run the chat server:
cargo run
- Clients can connect to the chat server using a WebSocket client.
- Messages sent by clients will be distributed to all connected clients using the broker pattern.
- All messages sent by clients will be saved in the PostgreSQL database for future reference.
Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.
The server and the client are made in different projects using cargo new (proj_name)
then cargo build
. On running the code you write cargo run
for the server first then the client.