Skip to content

Set default binary for cargo run#36

Open
Aakanksha638 wants to merge 1 commit intowhamcloud:mainfrom
Aakanksha638:default-run-server
Open

Set default binary for cargo run#36
Aakanksha638 wants to merge 1 commit intowhamcloud:mainfrom
Aakanksha638:default-run-server

Conversation

@Aakanksha638
Copy link
Copy Markdown

Demo

🎥 [Watch demo video](https://youtu.be/0frLn6aajUw)

Summary

Implements the full simple-chat specification in Rust using Tokio for async I/O.

  • Non-blocking TCP server — each connection runs in its own tokio::spawn task
  • Shared Room using Arc<Mutex<HashMap<String, UnboundedSender>>> to manage connected users
  • Line-delimited JSON wire protocol with three client messages: join, send, leave
  • Unique username enforcement — race-condition safe
  • Messages broadcast to all users except the sender
  • Graceful cleanup on both explicit leave and abrupt disconnect
  • Interactive CLI client using tokio::select! to handle server messages and stdin simultaneously

Testing

  • 11 unit tests — JSON round-trips for all protocol variants + Room logic in isolation
  • 7 integration tests — real TCP connections on random OS-assigned ports covering join, broadcast, leave, duplicate username rejection, and send-before-join error

Bonus

  • ✅ Pre-commit hook (.git-hooks/pre-commit) — blocks commit if cargo fmt, cargo build, or cargo clippy fail
  • ✅ GitHub Actions CI (.github/workflows/ci.yml) — runs fmt + clippy + tests + end-to-end smoke test on every push

How to Run

# Start the server
cargo run --bin server -- --port 9000

# Connect as alice (new terminal)
cargo run --bin client -- --username alice --port 9000

# Connect as bob (new terminal)
cargo run --bin client -- --username bob --port 9000

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.

2 participants