Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Chat Server and Asynchronous Client for Simple Chat Application #13

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

nihalpasham
Copy link

@nihalpasham nihalpasham commented Oct 27, 2024

This pull request introduces a chat server and an asynchronous client implementation for the "simple-chat" challenge. The key features are:

Server:

  • User Management: Each user is uniquely identified by a username, ensuring uniqueness at connection.
  • Message Broadcasting: Messages sent by a user are broadcasted to all other connected users.
  • Disconnect Handling: Users can leave the chat using the leave command, removing them from the active user list.
  • Threading for Concurrency: Each client connection is handled in a separate thread, allowing for low-latency communication among multiple users.
  • Memory Efficiency: Utilizes Arc<Mutex<>> and Arc<String> for shared state management among threads, minimizing memory overhead.

Client:

  • Command-line and Environment Variable Support: Leverages the clap crate to accept host, port, and username as command-line arguments, with environment variables as fallbacks.
  • Asynchronous Networking: Employs TcpStream for server connections and mio for non-blocking I/O, ensuring a responsive client experience.
  • Event Handling: Listens for incoming messages from the server and user inputs, facilitating real-time interaction.
  • Interactive Messaging: Users can send messages with send <MSG> and disconnect with the leave command.

Usage:

To run the server, execute

cd chat-server
cargo run

To run the client, execute:

cd async-chat-client
cargo run -- --host <HOST> --port <PORT> --username "<USERNAME>"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant