Sometimes a service cannot be found if computer is not connected to the internet

asked 2020-12-03 20:24:17 -0600

erinliu gravatar image

HI: I came across a random problem. If my computer is not connected to the internet, a client send request to a service , the service cannot be found in the network.But at the same time ,publishers and subscribers work well. Once I connect the computer to Internet, the service will turn to normal. Does anyone have any ideas?

if(!rclcpp::ok()){
    RCLCPP_WARN(nh_->get_logger(), "Interrupted while waiting for the  service. Exiting.");
}
if(!client->wait_for_service(std::chrono::seconds(1))){
    RCLCPP_WARN(nh_->get_logger(), "Can not find  service in the network in 1 second");
}
 auto result = client->async_send_request(request);
// Wait for the result.
if (rclcpp::spin_until_future_complete(node, result,std::chrono::seconds(1)) == 
 rclcpp::executor::FutureReturnCode::SUCCESS)
{
      result.get();
} else {
      RCLCPP_WARN(nh_->get_logger(), "Failed to get response of  service in 1 second");
}
edit retag flag offensive close merge delete