A multi-client TCP chat server where clients connect via TCP, register nickname, list users, send direct messages and broadcasts messages to groups.
- Go 1.22+ (tested with Go 1.22.2)
From the project root(where go.mod is)
go run ./cmd/serverFrom the project root(where go.mod is)
go run ./cmd/clientYou can start many clients with different terminals to test
Commands are case-insensitive
Set or change a nickname.
-
Must start with alphabet optionally followed by alphanemeric or underscore. Up to 10 characters.
-
Fail when the nickname is taken.
Example:
/nck homer
Show list of registered nicknames.
Example:
/LST
Send message to recipients.
- Must set nickname first.
Examples:
/MSG homer hello homer
/msg homer,bart hello simpson!
Register a group for registered users.
- Group name must start with # followed by alphabet and optionally followed by alphanumeric or underscore character. Up to 11 characters.
Example:
/GRP #simpson homer,bart
/MSG #simpson hello simpson!
- Server listens on port 6666 and accepts clients.
- Each client connection starts a new goroutine (
HandleConnection). - Client goroutines send
Messageinto a sharedmessageschannel. - Server retrieves
Messagefrommessageschannel and replies throughReplieschannel which each client has.
This design avoids shared mutable state between goroutines.
Refer to Architecture.md for detailed internal structure.