0
$\begingroup$

Rosanswers logo

Hi all,

I have the a problem that messages from Python and C++ Publisher cannot be received 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 1.rostopic pub command, or via 2. C++ file or 3. Python code Publisher, then I get the 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. I use Ubuntu 10.04 ROS version Diamondback...

regards

------------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

Comment 3 by [email protected], Yesterday (19 hours 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;
  }
}

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

Originally posted by safzam on ROS Answers with karma: 111 on 2011-11-20

Post score: 0


Original comments

Comment by safzam on 2011-12-13:
Hi am sorry to say that I gives same error after it worked. Now I think this is not an issue, may be some otherthing needs to be fixed. I changed DEFAULT_MASTER_URI from http://localhost:11311/ to http://szaman:11311/ in NodeConfiguration.java and rosmaked to both rosjava and rosjava_bootstrap

Comment by safzam on 2011-12-12:
Hi, I have just find that NodeConfiguration.java has DEFAULT_MASTER_URI. I changed it from localhost to szama. Now it works. now Thanks. regards

Comment by safzam on 2011-12-12:
Hi, I still get the same error, yes I run all the nodes on the same machine. when I run roscore I see ROS_MASTER_URI=http://szaman:11311 , but in above java program where I need to show that right interface is which? Can you point out it ? thanks

Comment by Ben_S on 2011-11-20:
Are your nodes all running on the same machine? How does your network-configuration look like (rosmaster-uri)? In rosjava you have to explicitly make sure it uses the right interface. By default it will use localhost/127.0.0.1.

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Your network seems to be unreachable. Please make sure you have followed all steps to set up your network correctly.


Originally posted by Martin Günther with karma: 11816 on 2011-11-21

This answer was ACCEPTED on the original site

Post score: 0


Original comments

Comment by safzam on 2011-12-13:
Hi am sorry to say that I gives same error after it worked. Now I think this is not an issue, may be some otherthing needs to be fixed. I changed DEFAULT_MASTER_URI from http://localhost:11311/ to http://szaman:11311/ in NodeConfiguration.java and rosmaked to both rosjava and rosjava_bootstrap

Comment by safzam on 2011-12-12:
Hi, I have just find that NodeConfiguration.java has DEFAULT_MASTER_URI. I changed it from localhost to szama. Now it works. now Thanks. regards

Comment by safzam on 2011-12-12:
Hi, thanks, I am not using two machines. Its only my one computer where I run different nodes. I still get the same error :-(

$\endgroup$

Your Answer

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