Implement async chat server and CLI client#35
Open
SonicDev111 wants to merge 1 commit intowhamcloud:mainfrom
Open
Implement async chat server and CLI client#35SonicDev111 wants to merge 1 commit intowhamcloud:mainfrom
SonicDev111 wants to merge 1 commit intowhamcloud:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Full implementation of the simple-chat assignment: an async TCP chat server and interactive CLI client, built with Tokio.
Author
ShivendraArchitecture
The project is a Cargo workspace with three crates:
protocol— shared message types (ClientMessage,ServerMessage) serialized as newline-delimited JSON viaserde_jsonserver— async TCP server binary backed by aserver_liblibrary crateclient— async CLI client binaryServer
Roommanages connected users in aHashMap<String, broadcast::Sender>protected by astd::sync::Mutex(held only for bookkeeping, never across await points)tokio::sync::broadcastchannel — messages are fanned out to all other users with zero copying of the sender's own messagesErrormessage and are droppedLeavemessages and TCP disconnects triggerleave()cleanup and notify remaining usersClient
--host,--port,--usernameas CLI flags orCHAT_HOST,CHAT_PORT,CHAT_USERNAMEenvironment variables (viaclap)Joinon startupsend <MSG>— broadcasts a message to the roomleave— sends aLeavemessage and exits cleanlyTests
19 tests total, all passing:
protocolunit testsserver_lib::roomunit testsIntegration tests cover: single user join, duplicate username rejection, message broadcast, leave notification, join notification, sender does not receive own message, and multi-user chat.
Bonus
hooks/pre-commit— runscargo fmt --check,cargo clippy -- -D warnings, andcargo build.github/workflows/ci.yml) — runs on every push and PR:checkjob: fmt, clippy, build, and full test suiteintegrationjob: starts the server, connects vianc, sends a message, and verifies clean exitChecklist
send <MSG>andleavecommandscargo fmt— no issuescargo clippy -- -D warnings— zero warnings