How to find out the publisher node for a certain received message?
Hi everyone!
I am currently writing a node to capture the network traffic between single nodes.Therefore my node subscribes to all published messages and sorts them - amongst others - according to their publisher. Since it is possible that different nodes publish the same topic I would like to know if there is a way to find out the publisher-node of a certain received message in my callback function.
Regards scr
EDIT:
Thanks for the hint on MessageEvents. In the meanwhile I also found that there exist MessageEvents, which can also be passed to the subscribers callback function. In cpp it can be used as shown HERE. Thereby you can simply use event.getPublisher() to obtain the publisher of a message.
However I need the publisher of a message in rosjava. There also exists a MessageEvent (org.jboss.netty.channel.MessageEvent) for rosjava. However it does not seem to contain the desired information (message publisher). Moreover I am not sure whether it can be used for a callback function as simple as in cpp. When I create subscriber as following I receive the Exception "Exception in thread "pool-1-thread-13" java.lang.ClassCastException: org.ros.internal.message.$Proxy3 cannot be cast to org.jboss.netty.channel.MessageEvent"
Code:
Subscriber<org.jboss.netty.channel.MessageEvent> subscriber = node.newSubscriber(topicType.getName(), topicType.getMessageType());
subscriber.addMessageListener(new MessageListener<org.jboss.netty.channel.MessageEvent>() {
@Override
public void onNewMessage(org.jboss.netty.channel.MessageEvent event) {
...
}
});
Do you know how to use MessageEvents in rosjava, or is there an other way to find out a messages publisher?
EDIT2: After some more research I found this post. So it seams it is currently not possible to access a messages publisher in the subscriber callback function. Is there probably a smart workaround?
Yes, use a callback signature that uses a [Message Event](http://www.ros.org/wiki/roscpp/Overview/Publishers%20and%20Subscribers#MessageEvent_.5BROS_1.1.2B-.5D).
Well, with java you'd have to look in the respective client API docs if something like that is supported. It looks like the MessageEvent you found is something totally else and unrelated to ROS.
Hi, thx for the reply. I also found an other post which suggests my request is currently not provided (see EDIT2). The MessageEvent is at least used in the SubscriberHandshakeHandler and Subscriber class of rosjava. Is there probably a smart workaround to simply retrieve the message publisher?