Robotics StackExchange | Archived questions

Are messages sent once per node or once per subscriber?

Hi! My question is related but not identical to this.

If there are N subscribers in one node on Machine A, that are all listening to the same publisher from Machine B over Wifi, how are the messages handled exactly?

  1. Is one message being transmitted over Wifi and duplicated N times locally on Machine A?
  2. Are N messages being transmitted over Wifi?
  3. If N messages are being transmitted, does this mean the publisher has to serialize the same message N times?

Asked by JunTuck on 2021-07-06 15:30:36 UTC

Comments

In ROS1, connections are peer-to-peer. I believe, option 2 is definitely Yes. About Option 3, i am not sure of implementation.

Asked by prince on 2021-07-07 00:42:43 UTC

For question 3, see rospy's publish behavior and roscpp's publish behavior (they are slightly different).

Asked by abhishek47 on 2021-07-07 02:25:25 UTC

This seems to be a duplicate of #q289237.

From that answer:

Once all copies of a specific Subscriber go out of scope, the subscription callback associated with that handle will stop being called. Once all Subscriber for a given topic go out of scope the topic will be unsubscribed.

This implies that there may be multiple Subscriber (i.e., multiple callbacks) on the same topic.

Indeed, looking at roscpp/topic_manager.cpp, we can see that subscribe first attempts to reuse an existing Subscription on the requested topic. If there is one, the new callback is appended to the Subscription's list of callbacks (std::vector<CallbackInfoPtr>).

this corresponds to my own understanding and the roscpp documentation for NodeHandle::subscribe(..), which mentions shared_ptrs passed to callbacks must not be used to change the incoming msg.

This answer focuses on roscpp of course. But @JunTuck has not specified which client library he/she's using.

Asked by gvdhoorn on 2021-07-07 04:15:39 UTC

Answers