Break out of loop when connection ends