Search code examples
yarp

Error: cannot connect to /root port; port port_name failed to activate (invalid address)


I'm a beginner in using YARP. My goal is to create two ports, and connect them (I'm using an Ubuntu virtual machine). The writer should receive inputs from the command line through the argv pointer.

When I run the code:

#include <yarp/os/all.h>
#include <iostream>

using namespace yarp::os;

int main(int argc, char *argv[]) {
int i = 0;

    // Set up YARP
    Network yarp;

    // Create port
    Port pout;
    bool ok  = pout.open("/examples/port/sender");
    if (!ok) {
        std::cerr << "Failed to open port" << std::endl;
        return 1;
    }

    // waiting for the receiver before transmitting
    yarp.waitConnection("/examples/port/sender", "/examples/port/receiver");

    // send data in a loop
    for(i = 0; i < argc; i++) {
        Bottle b;
        int x = atoi(argv[i]);
        b.addInt(x);
        std::cout << "Sending " << x << " message " << std::endl;
        pout.write(b);
    }

    // close port
    pout.close();

    return 0;
}

I got the following errors:

[ERROR] |yarp.os.Network| Cannot connect to port /root
[ERROR] |yarp.os.Port| Port /examples/port/sender failed to activate (invalid address)
Failed to open port

Can you tell me what is the mistake I did please?


Solution

  • Both errors come from the same issue:

    [ERROR] |yarp.os.Network| Cannot connect to port /root
    

    This means that the /root is not available when you run the executable. The /root port is the port used by yarp server (Unless you change the default "namespace").

    To fix this error you should just run yarp server on a different shell.

    [ERROR] |yarp.os.Port| Port /examples/port/sender failed to activate (invalid address)
    

    The /root port cannot be contacted, and therefore YARP is trying to open a port on an invalid address. It should be fixed as well as soon as you run the executable while the yarp server is running.

    You can find a very basic tutorial about ports here: http://www.yarp.it/git-master/note_ports.html