Prefer log.Fatalf
Handle byte equality without converting to string
Remove extra variable
Don't reallocate msg buffer for every message
Abstract writeMessage function
Add tests around user
Don't call Error on err
Return trimmed string directly
Defer closing of connection