Added error handling for Socket error