This project is a simple asynchronous TCP chat server and client application built using Tokio, a Rust asynchronous runtime. The server supports multiple clients connecting to it and provides features like broadcasting messages, listing connected users, and sending private messages.
- Multi-client support: Multiple clients can connect to the server and interact simultaneously.
- Message broadcasting: Each message sent by a client is broadcast to all other connected clients.
- User listing: Clients can view a list of currently connected users.
- Private messaging: Clients can send direct messages to specific users.
- Asynchronous I/O: Uses Tokio's async runtime for non-blocking I/O operations.
main.rs: Contains the main function to run the server.lib.rs: (to be created) A placeholder for library functions to modularize server and client code.Cargo.toml: Manages dependencies, including Tokio.
-
Clone the repository:
git clone https://github.com/devanshsonii/terminal-chat cd terminal-chat -
Add dependencies: Ensure
tokiois in the[dependencies]section ofCargo.toml.[dependencies] tokio = { version = "1", features = ["full"] }
-
Build the project:
cargo build
-
Start the Server: Run the server in one terminal window.
cargo run
-
Start a Client: In a separate terminal, start a client.
cargo run --example user
-
Commands:
- Send a message to all users by simply typing your message and pressing Enter.
- List connected users by typing
/listand pressing Enter. - Send a private message using the format:
/pvt <username> <message>. - To disconnect, simply close the terminal or terminate the process.
Contributions are welcome! Please feel free to submit a pull request or open an issue.