added socket.error handling