Fixed socket error handling.