Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The not satisfying answer is: you don't know. ROS does not provide any mechanism to decide when all potential subscribers have established a connection with your publisher.

You could check the number of current subscribers but actually your node should neither know now care about that. So the recommended way is to write your publish/subscribe application in a way that it can handle this.

If you want to just send one message (e.g. announce a configuration or something similar) you might want to use a latched topic. Every future subscribe will then receive the latest published message.

The not satisfying answer is: you don't know. ROS does not provide any mechanism to decide when all potential subscribers have established a connection with your publisher.

You could sleep (as you already suggested) for an unknown amount of time or check the number of current subscribers but actually your node should neither know now care about that. So the recommended way is to write your publish/subscribe application in a way that it can handle this.

If you want to just send one message (e.g. announce a configuration or something similar) you might want to use a latched topic. Every future subscribe will then receive the latest published message.