Added detection for when connection to the server is lost.