Major refactoring of connection code

* Extracted common code for server and client in a separate file
* Implemented message-pump-thread logic for both client and server
* Fixed bugs around trimming new lines and sending message with no
terminating symbol
* Added to-do list to keep track of issues/features