Ask Your Question
0

Many to many service communication

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

maverik gravatar image

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

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 -0500

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 imagemaverik ( 2013-06-03 23:45:48 -0500 )edit

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

joq gravatar imagejoq ( 2013-06-04 16:42:56 -0500 )edit

"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 imageFrankAllen ( 2015-07-11 06:24:41 -0500 )edit
1

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

ahendrix gravatar imageahendrix ( 2015-07-11 18:26:10 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

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

Seen: 1,119 times

Last updated: Jun 03 '13