A multi-client chat application built in Rust, featuring a TCP server and client logic for real-time messaging. This project demonstrates the power of Rust's concurrency and networking capabilities while maintaining safe, efficient, and scalable code.
- Multi-client support: Connect multiple clients to the server simultaneously.
- Real-time messaging: Messages are broadcast to all connected clients.
- Thread-safe communication: Utilizes Rust's
mpsc
channels for safe message passing. - Asynchronous handling: Non-blocking socket operations for seamless performance.
- Project Overview
- Setup and Installation
- Server Logic
- Client Logic
- How to Run
- Future Enhancements
- Contributing
This chat application is divided into two parts:
- Server: A TCP-based server that manages client connections and broadcasts messages to all connected clients.
- Client: A TCP client that connects to the server and allows users to send and receive messages in real time.
- Rust installed on your system. You can install it via rustup.
- A terminal to run the server and client instances.
git clone https://github.com/dexter-xD/tcp_server_rust.git
cd tcp_server_rust
The server listens on a specified address and port (127.0.0.1:8080
by default) and handles the following:
- Accepting incoming client connections.
- Receiving messages from clients.
- Broadcasting messages to all connected clients.
Code Highlights:
- Non-blocking Sockets: Allows seamless communication without halting the server.
- Concurrency with Threads: Each client connection is handled in its own thread.
- Message Broadcasting: Uses an
mpsc
channel to safely share messages across threads.
You can find the server code in the server.rs
file.
The client connects to the server, enabling users to:
- Send messages to the server.
- Receive messages broadcast by the server.
Features:
- Handles server disconnection gracefully.
- Provides an intuitive terminal-based interface for chatting.
Client logic will be implemented in Part 2 of this project. Stay tuned for updates!
- Navigate to the server directory.
- Run the server:
cargo run --bin server
- The server will start listening for connections on
127.0.0.1:8080
.
- Navigate to the client directory.
- Run the client:
cargo run --bin server
Stay tuned for updates and happy coding! 🦀