0
$\begingroup$

Rosanswers logo

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?


Originally posted by sacrif on ROS Answers with karma: 11 on 2012-08-15

Post score: 0


Original comments

Comment by dornhege on 2012-08-15:
Yes, use a callback signature that uses a Message Event.

Comment by dornhege on 2012-08-16:
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.

Comment by sacrif on 2012-08-16:
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?

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Why do you need that information?

The usual ROS practice is to distinguish topics, but decouple subscribers from worrying about which node published each message.

To work around that: add a source field to your message (or wrap some standard message in a custom message containing one), and define constants for the message sources you wish to distinguish. Then clients can tell the source without needing to worry about other nodes coming, going and restarting.

I did something similar in this custom message.


Originally posted by joq with karma: 25443 on 2012-08-16

This answer was ACCEPTED on the original site

Post score: 2

$\endgroup$

Your Answer

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