hub-server
https://github.com/alankritjoshi/hub-client
Simple TCP-based chat server. Client can be found:Setup
go run server.go 1234
How it works
- Use SyncMap for maintaining concurrent access to different clients
- Use Go Routines for handling connection
- Use handlers for input:
- "whoami" -> returns clientID of the requesting client
- "whoelse" -> returns space-separated clientIDs connected to server apart from requesting client
- "send [message] [clientID 1] [clientID 2] ... [clientID 3]" -> sends [message] to specified space-separated clientIDs
Checks in place
- Hard limit of 255 simultaneous connections
- Rejection of commands other than described above
Testing
Manual Testing
- Tested basic functionality
- Spun up 100 chat connections using a script and applied a sequence of 1. whoelse and 2. send [random_word] [list of clientIDs from 1.]
Unit Testing
- Unable to make connection mocking work in interest of time so added a unit test outline once connection mocking is available
To Improve
- Use structs to simplify data sharing for handlers
- Use better error handling structs/package for consistent error to the client
- Figure out how to mock connections for unit tests
- Find an optimal way of making the "whoelse" handler work. I forgot that there's no concept of sets in GoLang but the Map can be utilized better instead of printing each clientID on the fly