Added logic for failure to connect

Included, in comments at the bottom, suggestions on how to handle the server shutting down.