Exit loop when server closes the connection.