Handle socket error conditions more gracefully.