Connection and Trailing Spaces

* Removed trailing spaces of files
* Change connection status. If connection failed, the client must be closed
* Reconnect if an error occurs