0
$\begingroup$

Rosanswers logo

Hi all,

I am having a basic issue with publishing and subscribing to topics. Before I get into the core of the problem, I would like to ask a very simple question with respect to the "beginner_tutorial" package. In this package, there exists the "talker" and the "listener" nodes. When I run the talker node followed by the listener node, the listener subscribes to the topic published by the talker. However, if I run the listener node first it does not subscribe (which is correct as talker is not publishing). But why does it not start subscribing as soon as I run the talker node after a while? Basically, why does the subscriber automatically not understand when the talker starts publishing and latch on to it if I first run the subscriber followed by the publisher node? Thanks a lot.


Originally posted by Ashesh Goswami on ROS Answers with karma: 36 on 2014-08-06

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

When a new publisher becomes active:

  1. It informs the ROS master.
  2. The ROS master sends a callback to all of the nodes that are subscribed to that topic, informing them that there is a new publisher, and giving its address.
  3. The subscribers then use this address to open a new connection directly to the publisher so that they can receive messages.
  4. messages are then passed over this TCP socket from publisher to subscriber

All of the steps in this process take a nonzero amount of time. The end result is usually that the first one or two messages sent by the publisher are not seen by subscribers.

This process can also fail if the master cannot contact the subscriber for some reason (for example, it can't resolve the hostname that the subscriber is running on), or if the subscriber cannot contact the publisher for some reason (again, hostname resolution is often the problem here).


Originally posted by ahendrix with karma: 47576 on 2014-08-06

This answer was ACCEPTED on the original site

Post score: 4


Original comments

Comment by Ashesh Goswami on 2014-08-06:
I see..so does that mean that the publisher needs to be publishing for the subscriber to subscribe to the topic being published by the publisher? In other words, the talker node needs to be running and publishing before I can run the listener node? thanks a lot

Comment by ahendrix on 2014-08-06:
No. You can start the publisher and the subscriber in any order.

Comment by Ashesh Goswami on 2014-08-06:
but thats the problem I am facing. If I start the talker first it works but if I start the talker(publisher) after the subscriber node, it does not. I am trying this with the default beginner_tutorial package. What do you think might be the issue? thanks

Comment by ahendrix on 2014-08-06:
"This process can also fail if the master cannot contact the subscriber for some reason (for example, it can't resolve the hostname that the subscriber is running on), or if the subscriber cannot contact the publisher for some reason (again, hostname resolution is often the problem here)."

Comment by Ashesh Goswami on 2014-08-06:
my bad I missed that part earlier..thanks!!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.