gok03 / rosjava

Automatically exported from code.google.com/p/rosjava
0 stars 0 forks source link

Problems receiving messages sent from python/C++ #68

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create and run a standard Listener, the subscribes
2. using rostopic pub send a message to it

What is the expected output? What do you see instead?
print out saying that the message was received

What version of the product are you using? On what operating system?
I'm using the latest version of rosjava, running on ros electric. My OS is 
ubuntu 11.04

Please provide any additional information below.
I found that with the same class, publishing the message from a java class 
worked fine, but didn't from C++ or Python. 

Original issue reported on code.google.com by dhadfiel...@gmail.com on 26 Oct 2011 at 5:21

GoogleCodeExporter commented 9 years ago
Could you provide some additional information? Look for stack traces? What is 
the type of the message you're publishing? Could you provide some sample code?

Original comment by damonkoh...@google.com on 11 Nov 2011 at 2:20

GoogleCodeExporter commented 9 years ago
Hi I have the same problem that Python and C++ Publisher cannot be receiveb by 
Java (rosjava based) Subscriber. Following are the codes and errors. Normally 
Listener.java and Talker.java are fine and works but when I try to send message 
through rostopic pub command, or via C++ file or Pyhton code Publisher, then I 
get the same error by the Java Listener (Subscriber). Please see all the files 
and associated generated Errors by the java node. Please Note that all three 
errors are same. Do you have any solution to fix it. Thanks in advance.

------------Listener.java------------
import org.apache.commons.logging.Log;
import org.ros.message.MessageListener;
import org.ros.node.Node;
import org.ros.node.NodeMain;
import org.ros.node.topic.Subscriber;

import com.google.common.base.Preconditions;

public class Listener implements NodeMain {

  private Node node;

  @Override
  public void main(Node node) {
    Preconditions.checkState(this.node == null);
    this.node = node;
    try {
      final Log log = node.getLog();
      node.newSubscriber("chatter", "std_msgs/String",
          new MessageListener<org.ros.message.std_msgs.String>() {
            @Override
            public void onNewMessage(org.ros.message.std_msgs.String message) {
              log.info("I heard: \"" + message.data + "\"");
            }
          });
    } catch (Exception e) {
      if (node != null) {
        node.getLog().fatal(e);
      } else {
        e.printStackTrace();
      }
    }
  }

  @Override
  public void shutdown() {
    node.shutdown();
    node = null;
  }

}

-----------Talker.java---------------
import com.google.common.base.Preconditions;
import org.ros.node.Node;
import org.ros.node.NodeMain;
import org.ros.node.topic.Publisher;

public class Talker implements NodeMain {

  private Node node;

  @Override
  public void main(Node node) {
    Preconditions.checkState(this.node == null);
    this.node = node;
    try {
      Publisher<org.ros.message.std_msgs.String> publisher =
          node.newPublisher("chatter", "std_msgs/String");
      int seq = 0;
      while (true) {
        org.ros.message.std_msgs.String str = new org.ros.message.std_msgs.String();
        str.data = "Hello world! " + seq;
        publisher.publish(str);
        node.getLog().info("Hello, world! " + seq);
        seq++;
        Thread.sleep(1000);
      }
    } catch (Exception e) {
      if (node != null) {
        node.getLog().fatal(e);
      } else {
        e.printStackTrace();
      }
    }
  }

  @Override
  public void shutdown() {
    node.shutdown();
    node = null;
  }
}

1.
rostopic pub /chatter std_gs/String "hello"

20.11.2011 11:00:42 org.jboss.netty.channel.DefaultChannelPipeline
WARNUNG: An exception was thrown by a user handler while handling an exception 
event ([id: 0x3b3e0aba] EXCEPTION: java.net.SocketException: Network is 
unreachable)
org.ros.exception.RosRuntimeException: java.net.SocketException: Network is 
unreachable
    at org.ros.internal.transport.ConnectionTrackingHandler.exceptionCaught(ConnectionTrackingHandler.java:63)
    at org.jboss.netty.channel.Channels.fireExceptionCaught(Channels.java:432)
    at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink.connect(NioClientSocketPipelineSink.java:158)
    at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink.eventSunk(NioClientSocketPipelineSink.java:103)
    at org.jboss.netty.handler.codec.oneone.OneToOneEncoder.handleDownstream(OneToOneEncoder.java:60)
    at org.jboss.netty.channel.Channels.connect(Channels.java:541)
    at org.jboss.netty.channel.AbstractChannel.connect(AbstractChannel.java:218)
    at org.jboss.netty.bootstrap.ClientBootstrap.connect(ClientBootstrap.java:227)
    at org.jboss.netty.bootstrap.ClientBootstrap.connect(ClientBootstrap.java:188)
    at org.ros.internal.node.topic.DefaultSubscriber.addPublisher(DefaultSubscriber.java:160)
    at org.ros.internal.node.topic.UpdatePublisherRunnable.run(UpdatePublisherRunnable.java:69)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:636)
Caused by: java.net.SocketException: Network is unreachable
    at sun.nio.ch.Net.connect(Native Method)
    at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:525)
    at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink.connect(NioClientSocketPipelineSink.java:140)
    ... 11 more
20.11.2011 11:00:42 org.ros.internal.node.topic.UpdatePublisherRunnable run
SCHWERWIEGEND: org.ros.exception.RosRuntimeException: java.net.SocketException: 
Network is unreachable

---------------Talker.cpp---------------------
2.
#include <ros/ros.h>
#include <std_msgs/String.h>
#include <mbd_msgs/Observations.h>
#include <sstream>
int main(int argc, char** argv)
{
  ros::init(argc, argv, "talker1");
  ros::NodeHandle n;
  ros::Publisher chatter_pub = n.advertise<std_msgs::String>("chatter", 100);
  ros::Rate loop_rate(5);
  int count = 0;
  while (ros::ok())
  {
    std::stringstream ss;
    ss << "Hello there! This is message [" << count << "]";
    std_msgs::String msg;
    msg.data = ss.str();
    chatter_pub.publish(msg);
    ROS_INFO("I published [%s]", ss.str().c_str());
    ros::spinOnce();
    loop_rate.sleep();
    ++count;
  }
}

20.11.2011 11:02:41 org.jboss.netty.channel.DefaultChannelPipeline
WARNUNG: An exception was thrown by a user handler while handling an exception 
event ([id: 0x2be2befa] EXCEPTION: java.net.SocketException: Network is 
unreachable)
org.ros.exception.RosRuntimeException: java.net.SocketException: Network is 
unreachable
    at org.ros.internal.transport.ConnectionTrackingHandler.exceptionCaught(ConnectionTrackingHandler.java:63)
    at org.jboss.netty.channel.Channels.fireExceptionCaught(Channels.java:432)
    at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink.connect(NioClientSocketPipelineSink.java:158)
    at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink.eventSunk(NioClientSocketPipelineSink.java:103)
    at org.jboss.netty.handler.codec.oneone.OneToOneEncoder.handleDownstream(OneToOneEncoder.java:60)
    at org.jboss.netty.channel.Channels.connect(Channels.java:541)
    at org.jboss.netty.channel.AbstractChannel.connect(AbstractChannel.java:218)
    at org.jboss.netty.bootstrap.ClientBootstrap.connect(ClientBootstrap.java:227)
    at org.jboss.netty.bootstrap.ClientBootstrap.connect(ClientBootstrap.java:188)
    at org.ros.internal.node.topic.DefaultSubscriber.addPublisher(DefaultSubscriber.java:160)
    at org.ros.internal.node.topic.UpdatePublisherRunnable.run(UpdatePublisherRunnable.java:69)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:636)
Caused by: java.net.SocketException: Network is unreachable
    at sun.nio.ch.Net.connect(Native Method)
    at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:525)
    at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink.connect(NioClientSocketPipelineSink.java:140)
    ... 11 more
20.11.2011 11:02:41 org.ros.internal.node.topic.UpdatePublisherRunnable run
SCHWERWIEGEND: org.ros.exception.RosRuntimeException: java.net.SocketException: 
Network is unreachable

-----------Talker.py-----------------
#!/usr/bin/env python
import roslib; roslib.load_manifest('beginner_tutorials')
import rospy
from std_msgs.msg import String
def talker():
    pub = rospy.Publisher('chatter', String)
    rospy.init_node('talker')
    while not rospy.is_shutdown():
        str = "hello world %s"%rospy.get_time()
        rospy.loginfo(str)
        pub.publish(String(str))
        rospy.sleep(1.0)
if __name__ == '__main__':
    try:
        talker()
    except rospy.ROSInterruptException: pass

20.11.2011 11:05:47 org.jboss.netty.channel.DefaultChannelPipeline
WARNUNG: An exception was thrown by a user handler while handling an exception 
event ([id: 0x7eb1cc87] EXCEPTION: java.net.SocketException: Network is 
unreachable)
org.ros.exception.RosRuntimeException: java.net.SocketException: Network is 
unreachable
    at org.ros.internal.transport.ConnectionTrackingHandler.exceptionCaught(ConnectionTrackingHandler.java:63)
    at org.jboss.netty.channel.Channels.fireExceptionCaught(Channels.java:432)
    at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink.connect(NioClientSocketPipelineSink.java:158)
    at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink.eventSunk(NioClientSocketPipelineSink.java:103)
    at org.jboss.netty.handler.codec.oneone.OneToOneEncoder.handleDownstream(OneToOneEncoder.java:60)
    at org.jboss.netty.channel.Channels.connect(Channels.java:541)
    at org.jboss.netty.channel.AbstractChannel.connect(AbstractChannel.java:218)
    at org.jboss.netty.bootstrap.ClientBootstrap.connect(ClientBootstrap.java:227)
    at org.jboss.netty.bootstrap.ClientBootstrap.connect(ClientBootstrap.java:188)
    at org.ros.internal.node.topic.DefaultSubscriber.addPublisher(DefaultSubscriber.java:160)
    at org.ros.internal.node.topic.UpdatePublisherRunnable.run(UpdatePublisherRunnable.java:69)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:636)
Caused by: java.net.SocketException: Network is unreachable
    at sun.nio.ch.Net.connect(Native Method)
    at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:525)
    at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink.connect(NioClientSocketPipelineSink.java:140)
    ... 11 more
20.11.2011 11:05:47 org.ros.internal.node.topic.UpdatePublisherRunnable run
SCHWERWIEGEND: org.ros.exception.RosRuntimeException: java.net.SocketException: 
Network is unreachable

Original comment by szaman...@gmail.com on 20 Nov 2011 at 10:23

GoogleCodeExporter commented 9 years ago
Hi I have the same problem that Python and C++ Publisher cannot be receiveb by 
Java (rosjava based) Subscriber. Following are the codes and errors. Normally 
Listener.java and Talker.java are fine and works but when I try to send message 
through rostopic pub command, or via C++ file or Pyhton code Publisher, then I 
get the same error by the Java Listener (Subscriber). Please see all the files 
and associated generated Errors by the java node. Please Note that all three 
errors are same. Do you have any solution to fix it. Thanks in advance.

------------Listener.java------------
import org.apache.commons.logging.Log;
import org.ros.message.MessageListener;
import org.ros.node.Node;
import org.ros.node.NodeMain;
import org.ros.node.topic.Subscriber;

import com.google.common.base.Preconditions;

public class Listener implements NodeMain {

  private Node node;

  @Override
  public void main(Node node) {
    Preconditions.checkState(this.node == null);
    this.node = node;
    try {
      final Log log = node.getLog();
      node.newSubscriber("chatter", "std_msgs/String",
          new MessageListener<org.ros.message.std_msgs.String>() {
            @Override
            public void onNewMessage(org.ros.message.std_msgs.String message) {
              log.info("I heard: \"" + message.data + "\"");
            }
          });
    } catch (Exception e) {
      if (node != null) {
        node.getLog().fatal(e);
      } else {
        e.printStackTrace();
      }
    }
  }

  @Override
  public void shutdown() {
    node.shutdown();
    node = null;
  }

}

-----------Talker.java---------------
import com.google.common.base.Preconditions;
import org.ros.node.Node;
import org.ros.node.NodeMain;
import org.ros.node.topic.Publisher;

public class Talker implements NodeMain {

  private Node node;

  @Override
  public void main(Node node) {
    Preconditions.checkState(this.node == null);
    this.node = node;
    try {
      Publisher<org.ros.message.std_msgs.String> publisher =
          node.newPublisher("chatter", "std_msgs/String");
      int seq = 0;
      while (true) {
        org.ros.message.std_msgs.String str = new org.ros.message.std_msgs.String();
        str.data = "Hello world! " + seq;
        publisher.publish(str);
        node.getLog().info("Hello, world! " + seq);
        seq++;
        Thread.sleep(1000);
      }
    } catch (Exception e) {
      if (node != null) {
        node.getLog().fatal(e);
      } else {
        e.printStackTrace();
      }
    }
  }

  @Override
  public void shutdown() {
    node.shutdown();
    node = null;
  }
}

1.
rostopic pub /chatter std_gs/String "hello"

20.11.2011 11:00:42 org.jboss.netty.channel.DefaultChannelPipeline
WARNUNG: An exception was thrown by a user handler while handling an exception 
event ([id: 0x3b3e0aba] EXCEPTION: java.net.SocketException: Network is 
unreachable)
org.ros.exception.RosRuntimeException: java.net.SocketException: Network is 
unreachable
    at org.ros.internal.transport.ConnectionTrackingHandler.exceptionCaught(ConnectionTrackingHandler.java:63)
    at org.jboss.netty.channel.Channels.fireExceptionCaught(Channels.java:432)
    at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink.connect(NioClientSocketPipelineSink.java:158)
    at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink.eventSunk(NioClientSocketPipelineSink.java:103)
    at org.jboss.netty.handler.codec.oneone.OneToOneEncoder.handleDownstream(OneToOneEncoder.java:60)
    at org.jboss.netty.channel.Channels.connect(Channels.java:541)
    at org.jboss.netty.channel.AbstractChannel.connect(AbstractChannel.java:218)
    at org.jboss.netty.bootstrap.ClientBootstrap.connect(ClientBootstrap.java:227)
    at org.jboss.netty.bootstrap.ClientBootstrap.connect(ClientBootstrap.java:188)
    at org.ros.internal.node.topic.DefaultSubscriber.addPublisher(DefaultSubscriber.java:160)
    at org.ros.internal.node.topic.UpdatePublisherRunnable.run(UpdatePublisherRunnable.java:69)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:636)
Caused by: java.net.SocketException: Network is unreachable
    at sun.nio.ch.Net.connect(Native Method)
    at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:525)
    at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink.connect(NioClientSocketPipelineSink.java:140)
    ... 11 more
20.11.2011 11:00:42 org.ros.internal.node.topic.UpdatePublisherRunnable run
SCHWERWIEGEND: org.ros.exception.RosRuntimeException: java.net.SocketException: 
Network is unreachable

---------------Talker.cpp---------------------
2.
#include <ros/ros.h>
#include <std_msgs/String.h>
#include <mbd_msgs/Observations.h>
#include <sstream>
int main(int argc, char** argv)
{
  ros::init(argc, argv, "talker1");
  ros::NodeHandle n;
  ros::Publisher chatter_pub = n.advertise<std_msgs::String>("chatter", 100);
  ros::Rate loop_rate(5);
  int count = 0;
  while (ros::ok())
  {
    std::stringstream ss;
    ss << "Hello there! This is message [" << count << "]";
    std_msgs::String msg;
    msg.data = ss.str();
    chatter_pub.publish(msg);
    ROS_INFO("I published [%s]", ss.str().c_str());
    ros::spinOnce();
    loop_rate.sleep();
    ++count;
  }
}

20.11.2011 11:02:41 org.jboss.netty.channel.DefaultChannelPipeline
WARNUNG: An exception was thrown by a user handler while handling an exception 
event ([id: 0x2be2befa] EXCEPTION: java.net.SocketException: Network is 
unreachable)
org.ros.exception.RosRuntimeException: java.net.SocketException: Network is 
unreachable
    at org.ros.internal.transport.ConnectionTrackingHandler.exceptionCaught(ConnectionTrackingHandler.java:63)
    at org.jboss.netty.channel.Channels.fireExceptionCaught(Channels.java:432)
    at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink.connect(NioClientSocketPipelineSink.java:158)
    at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink.eventSunk(NioClientSocketPipelineSink.java:103)
    at org.jboss.netty.handler.codec.oneone.OneToOneEncoder.handleDownstream(OneToOneEncoder.java:60)
    at org.jboss.netty.channel.Channels.connect(Channels.java:541)
    at org.jboss.netty.channel.AbstractChannel.connect(AbstractChannel.java:218)
    at org.jboss.netty.bootstrap.ClientBootstrap.connect(ClientBootstrap.java:227)
    at org.jboss.netty.bootstrap.ClientBootstrap.connect(ClientBootstrap.java:188)
    at org.ros.internal.node.topic.DefaultSubscriber.addPublisher(DefaultSubscriber.java:160)
    at org.ros.internal.node.topic.UpdatePublisherRunnable.run(UpdatePublisherRunnable.java:69)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:636)
Caused by: java.net.SocketException: Network is unreachable
    at sun.nio.ch.Net.connect(Native Method)
    at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:525)
    at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink.connect(NioClientSocketPipelineSink.java:140)
    ... 11 more
20.11.2011 11:02:41 org.ros.internal.node.topic.UpdatePublisherRunnable run
SCHWERWIEGEND: org.ros.exception.RosRuntimeException: java.net.SocketException: 
Network is unreachable

-----------Talker.py-----------------
#!/usr/bin/env python
import roslib; roslib.load_manifest('beginner_tutorials')
import rospy
from std_msgs.msg import String
def talker():
    pub = rospy.Publisher('chatter', String)
    rospy.init_node('talker')
    while not rospy.is_shutdown():
        str = "hello world %s"%rospy.get_time()
        rospy.loginfo(str)
        pub.publish(String(str))
        rospy.sleep(1.0)
if __name__ == '__main__':
    try:
        talker()
    except rospy.ROSInterruptException: pass

20.11.2011 11:05:47 org.jboss.netty.channel.DefaultChannelPipeline
WARNUNG: An exception was thrown by a user handler while handling an exception 
event ([id: 0x7eb1cc87] EXCEPTION: java.net.SocketException: Network is 
unreachable)
org.ros.exception.RosRuntimeException: java.net.SocketException: Network is 
unreachable
    at org.ros.internal.transport.ConnectionTrackingHandler.exceptionCaught(ConnectionTrackingHandler.java:63)
    at org.jboss.netty.channel.Channels.fireExceptionCaught(Channels.java:432)
    at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink.connect(NioClientSocketPipelineSink.java:158)
    at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink.eventSunk(NioClientSocketPipelineSink.java:103)
    at org.jboss.netty.handler.codec.oneone.OneToOneEncoder.handleDownstream(OneToOneEncoder.java:60)
    at org.jboss.netty.channel.Channels.connect(Channels.java:541)
    at org.jboss.netty.channel.AbstractChannel.connect(AbstractChannel.java:218)
    at org.jboss.netty.bootstrap.ClientBootstrap.connect(ClientBootstrap.java:227)
    at org.jboss.netty.bootstrap.ClientBootstrap.connect(ClientBootstrap.java:188)
    at org.ros.internal.node.topic.DefaultSubscriber.addPublisher(DefaultSubscriber.java:160)
    at org.ros.internal.node.topic.UpdatePublisherRunnable.run(UpdatePublisherRunnable.java:69)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:636)
Caused by: java.net.SocketException: Network is unreachable
    at sun.nio.ch.Net.connect(Native Method)
    at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:525)
    at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink.connect(NioClientSocketPipelineSink.java:140)
    ... 11 more
20.11.2011 11:05:47 org.ros.internal.node.topic.UpdatePublisherRunnable run
SCHWERWIEGEND: org.ros.exception.RosRuntimeException: java.net.SocketException: 
Network is unreachable

Original comment by szaman...@gmail.com on 20 Nov 2011 at 1:28

GoogleCodeExporter commented 9 years ago
Can you check if this is still happening? Several changes have been made 
recently which may have fixed this.

Original comment by khug...@google.com on 19 Jan 2012 at 5:32

GoogleCodeExporter commented 9 years ago
I can't reproduce this. I assume it's fixed.

Original comment by damonkoh...@google.com on 5 Apr 2012 at 7:16