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

how to reconnect master on PC

asked 2012-04-16 00:06:20 -0500

rosdai gravatar image

updated 2012-04-16 00:17:05 -0500

Hi all,

I have an application for android which sends data from a nodemain to master on PC. onCreate I used connectmaster() to run a new NodeMain called Sender. now I want to add a reconnect function, which will kill this Sender and connect it to Master again.

I tried the following code:

   private void reconnectMaster()
       try {
       } catch (InterruptedException e) {
       Log.v(TAG, "shut down node sender");

   private void disconnectMaster(){



   public void connectmaster(){
           String Uri = ((EditText)findViewById(;
           Integer port = Integer.parseInt(((EditText)findViewById(;
           URI masterUri = URI.create("http://"+ Uri + ":" + port);
           Log.v("Sender", "setMasterURI");
           String localhost = InetAddressFactory.newNonLoopback().getHostAddress();
//           String localhost = "";
           Log.v("Sender", "setlocalhost");

           nodeConfiguration = NodeConfiguration.newPublic(localhost, masterUri);
           Log.v("Sender", "nodeConfiguration");

           Log.v("Sender", "nodeName");     

           }catch (Exception e) {
           Log.e("Sender", "nodeConfiguration error");

       Log.i("SDM", "create new Sender"); 
       sender = new Sender();
       nodeMainExecutor.execute(sender, nodeConfiguration);


and my Sender has the following code:

public class Sender implements NodeMain {

   public Publisher<ant_msgs.sdm> publisherSDM;
   public Publisher<ant_msgs.wgt> publisherWGT;
   public Publisher<ant_msgs.hrm> publisherHRM;
   private Node node;

public Sender() {
//     TODO Auto-generated constructor stub


  public GraphName getDefaultNodeName() {
    return new GraphName("Sender");

  public void onStart(Node node) {
      Log.i("Sender", "enter onStart");
      this.node = node;
      publisherSDM = node.newPublisher("ANT", ant_msgs.sdm._TYPE);


  public void publishSDM(float speed, float cadence, float distance, long stride, String data)
      Log.i("Sender", "publishSDM enter");

      ant_msgs.sdm msg = publisherSDM.newMessage();

  public void onShutdown(Node node) {
      Log.i("sender", "onShutdown");
      node = null;

  public void onShutdownComplete(Node node) {

but every time i click on the button reconnect, hundreds of "onShutDown" is shown in my logcat (which is in my Sender's shutdown method log.v), and then the application broke down

04-16 11:54:17.437: I/Registrar(7170): Unregistering publisher: Publisher<PublisherDefinition<PublisherIdentifier<NodeSlaveIdentifier</Ant_Sender,>, TopicIdentifier</rosout>>, Topic<TopicIdentifier</rosout>, TopicDescription<rosgraph_msgs/Log,acffd30cd6b6de30f120938c17c593fb>>>>
04-16 11:54:17.437: W/Registrar(7170): Registrar no longer running, request ignored.
04-16 11:54:17.757: I/DefaultPublisher(7170): Publisher unregistration failed: Publisher<PublisherDefinition<PublisherIdentifier<NodeSlaveIdentifier</Ant_Sender,>, TopicIdentifier</rosout>>, Topic<TopicIdentifier</rosout>, TopicDescription<rosgraph_msgs/Log,acffd30cd6b6de30f120938c17c593fb>>>>

04-16 11:53:28.430: E/dalvikvm(5334): Thread creation failed (err=No such file or directory)
04-16 11:53:28.430: D/AndroidRuntime(5334): Shutting down VM
04-16 11:53:28.430: W/dalvikvm(5334): threadid=1: thread exiting with uncaught exception (group=0x40018560)
04-16 11:53:28.437: E/AndroidRuntime(5334): FATAL EXCEPTION: main
04-16 11:53:28.437: E/AndroidRuntime(5334): java.lang.OutOfMemoryError: thread creation failed
04-16 11:53:28.437: E/AndroidRuntime(5334):     at java.lang.VMThread.create(Native Method)
04-16 11:53:28.437: E/AndroidRuntime(5334):     at java.lang.Thread ...
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2012-04-16 01:16:46 -0500

rosdai gravatar image

I found a solution: just delete the content in onShutDown method in Sender

I didn't really understand what onShutDown does. instead of shutting down the node, onShutDown is a user specified function that is called when the node is shut down by the system.

edit flag offensive delete link more

Question Tools


Asked: 2012-04-16 00:06:20 -0500

Seen: 739 times

Last updated: Apr 16 '12