ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Many to many service communication

asked 2013-06-03 00:21:46 -0600

maverik gravatar image

updated 2013-06-03 05:08:41 -0600

Hi all,

as far as I understood a service can be used by different clients as long as in the source code the ServiceServer and the ServiceClient are declared with the same service name (see code below, each line belongs to a different node).

ros::ServiceServer service = n.advertiseService("add_two_ints", add);
ros::ServiceClient client1 = n.serviceClient<beginner_tutorials::AddTwoInts>("add_two_ints");
ros::ServiceClient client2 = n.serviceClient<beginner_tutorials::AddTwoInts>("add_two_ints");

How are multiple concurrent requests managed? As far as I understood they are processed in a synchronous way according to a FIFO policy, right?

I'm also wondering if it is possible to have a many-to-many connection (multiple servers)

ros::ServiceServer service = n.advertiseService("add_two_ints", add);
ros::ServiceServer service2 = n.advertiseService("add_two_ints", add);
    ros::ServiceClient client1 = n.serviceClient<beginner_tutorials::AddTwoInts>("add_two_ints");
    ros::ServiceClient client2 = n.serviceClient<beginner_tutorials::AddTwoInts>("add_two_ints");

How are requests managed in this case?

Finally, are these concepts valid also for actions?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
4

answered 2013-06-03 15:17:00 -0600

ahendrix gravatar image

You cannot have multiple nodes advertising the same service, and you cannot advertise the same service more than once from the same node; this doesn't make sense given that services are effectively remote function calls.

I'm not certain, but I believe service requests are handled serially by design.

If you want many-to-many communication, topics may be a better choice.

edit flag offensive delete link more

Comments

Thanks! What you said makes sense from a theoretical point of view! However I tried to create two nodes that advertise the same service and when I lunched them I didn't see any error. However the services were always provided by the same node, probably the second I lunched.

maverik gravatar image maverik  ( 2013-06-03 23:45:48 -0600 )edit

For topics, the publisher advertises. The many-to-one typically means many subscribers.

joq gravatar image joq  ( 2013-06-04 16:42:56 -0600 )edit
1

"I'm not certain, but I believe service requests are handled serially by design." - this is true on the client side, but the service provider executes requests concurrently on separate threads... at least in rospy.

FrankAllen gravatar image FrankAllen  ( 2015-07-11 06:24:41 -0600 )edit
2

roscpp handles service requests serially, unless you explicitly create a multithreaded async spinner to handle service callbacks.

ahendrix gravatar image ahendrix  ( 2015-07-11 18:26:10 -0600 )edit

Question Tools

Stats

Asked: 2013-06-03 00:21:46 -0600

Seen: 2,067 times

Last updated: Jun 03 '13