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

Revision history [back]

click to hide/show revision 1
initial version

There aren't a lot of good reasons for wanting to do this, because it breaks the anonymity of the Anonymous publish/subscribe data flow model. It can be useful for debugging, but building functional logic that depends on the publisher name it is not usually a good idea.

Caveats aside, you can access the publisher name by subscribing to the MessageEvent<msgtype> object (templated on your actual message type), which contains additional metadata in addition to the message data. Have a look at the MessageEvent subsection of the ROSCPP Publishers and Subscribers page for the details.