【问题标题】:Error: cannot connect to /root port; port port_name failed to activate (invalid address)错误:无法连接到 /root 端口;端口 port_name 未能激活(地址无效)
【发布时间】:2021-03-18 12:14:29
【问题描述】:

我是使用 YARP 的初学者。我的目标是创建两个端口并连接它们(我使用的是 Ubuntu 虚拟机)。 writer 应该通过 argv 指针接收来自命令行的输入。

当我运行代码时:

#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;
}

我收到以下错误:

[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

你能告诉我我做错了什么吗?

【问题讨论】:

    标签: yarp


    【解决方案1】:

    两个错误都来自同一个问题:

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

    这意味着当您运行可执行文件时,/root 不可用。 /root 端口是yarp server 使用的端口(除非您更改默认的“命名空间”)。

    要修复此错误,您只需在不同的 shell 上运行 yarp server

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

    无法联系/root 端口,因此 YARP 试图打开无效地址上的端口。在yarp server 运行时运行可执行文件后,它应该被修复。

    您可以在此处找到有关端口的非常基本的教程:http://www.yarp.it/git-master/note_ports.html

    【讨论】:

    • 非常感谢@DanieleE.Domenichelli 的有用回答。
    猜你喜欢
    • 2015-05-22
    • 2014-01-21
    • 2016-09-05
    • 2020-02-18
    • 1970-01-01
    • 2019-02-02
    • 2018-08-01
    • 2017-12-10
    • 1970-01-01
    相关资源
    最近更新 更多