apollo icon indicating copy to clipboard operation
apollo copied to clipboard

Reader Writer在同主机上CYBER_IP不为127.0.0.1则不能通信

Open zhenghaidily opened this issue 3 years ago • 1 comments

在学习cyber rt,版本为6.0 有一个主机: ip地址为192.168.5.106,如果CYBER_IP=192.158.5.106,则listener和talker通信失败,CYBER_IP=127.0.0.1则可以通信. 有两个主机,ip为192.168.5.106和192.168.5.206: CYBER_IP=127.0.0.1,192.168.5.106上的talker和192.168.5.206上的listener无法通信; CYBER_IP=192.158.5.106 和 CYBER_IP=192.158.5.206,192.168.5.106上的talker和192.168.5.206上的listener可以通信.

zhenghaidily avatar Sep 02 '22 09:09 zhenghaidily

在验证的时候发现是eprosima::fastrtps::Publisher和eprosima::fastrtps::Subscriber,在ip是是127.0.0.1的时候,可以订阅到本地的发布,但是ip配置成主机ip的时候,发布的时候,没有订阅到发布的消息: std::string ip_env("127.0.0.1"); const char* ip_val = ::getenv("CYBER_IP"); if (ip_val != nullptr) { ip_env = ip_val; if (ip_env.empty()) { AERROR << "invalid CYBER_IP (an empty string)"; return; } } ADEBUG << "cyber ip: " << ip_env;

eprosima::fastrtps::rtps::Locator_t locator;
locator.port = 0;
RETURN_IF(!locator.set_IP4_address(ip_env));

locator.kind = LOCATOR_KIND_UDPv4;

attr.rtps.defaultUnicastLocatorList.push_back(locator);
attr.rtps.defaultOutLocatorList.push_back(locator);
attr.rtps.builtin.metatrafficUnicastLocatorList.push_back(locator);

zhenghaidily avatar Sep 06 '22 06:09 zhenghaidily

@zhenghaidily 你的验证结果非常准确!所以你的问题是什么呢?如果是同一物理机,将会采用共享内存通信,如果是不同物理机,才会走socket通信,因此你的描述没有任何问题。

daohu527 avatar Oct 14 '22 04:10 daohu527

如果cyber_ip配置的是实际的ip地址,不是127.0.0.1,同一个物理机上节点间是不能通信的,如果一个节点的消息会被多个节点订阅,有的节点在同一物理机,有的节点在不同的物理机,那就会有一部分节点收不到消息

zhenghaidily avatar Oct 28 '22 09:10 zhenghaidily

是的,这可能是一个问题,我们可以把同一物理机上的节点合并。

daohu527 avatar Oct 28 '22 09:10 daohu527

是的,这可能是一个问题,我们可以把同一物理机上的节点合并。

但是这样无法使用本机的共享内存通信方式了啊。

fengmao31 avatar Mar 09 '23 10:03 fengmao31

I was wrong before. The communication between the local machine and the physical machine can be realized in the following ways

Make sure the two hosts(or more) are under the same network segment of the local area network, Like 192.168.10.6 and 192.168.10.7.

You just need to modify CYBER_IP of /apollo/cyber/setup.bash

export CYBER_IP=127.0.0.1

Suppose you have two hosts A and B,the ip of A is 192.168.10.6, and the ip of B is 192.168.10.7. Then set CYBER_IP to 192.168.10.6 on host A, and set CYBER_IP to 192.168.10.7 on host B. Now host A can communicate with host B.

daohu527 avatar Mar 09 '23 11:03 daohu527

但是我两个节点进程在一个物理机上面,一个节点进程在另一台物理机上面。发布者和其中一个订阅者在一个物理机上,另一个订阅者在另一个物理机上。 无法使得两个订阅者都可以订阅发布者的信息。然而fastdds项目本身是支持的,检测到本机IP进行共享内存。

fengmao31 avatar Mar 10 '23 01:03 fengmao31

it can be supported. at first, check your ip. maybe the router change your ip. secondly, maybe you need create a new node. in this part, apollo have a bug, it don't show you a error message about same node is be used in another device. it only show the message when you try to run same node in local device.

fengmao31 avatar Mar 13 '23 03:03 fengmao31

但是我两个节点进程在一个物理机上面,一个节点进程在另一台物理机上面。发布者和其中一个订阅者在一个物理机上,另一个订阅者在另一个物理机上。 无法使得两个订阅者都可以订阅发布者的信息。然而fastdds项目本身是支持的,检测到本机IP进行共享内存。

因为cyber rt用的fastdds 是1.5.0版本的 还不支持共享内存方式

freekevinCode avatar Aug 11 '23 07:08 freekevinCode

但是我两个节点进程在一个物理机上面,一个节点进程在另一台物理机上面。发布者和其中一个订阅者在一个物理机上,另一个订阅者在另一个物理机上。 无法使得两个订阅者都可以订阅发布者的信息。然而fastdds项目本身是支持的,检测到本机IP进行共享内存。

因为cyber rt用的fastdds 是1.5.0版本的 还不支持共享内存方式

cyber rt里面有百度自己实现的一套共享内存。我是指那套共享内存。

fengmao31 avatar Aug 14 '23 13:08 fengmao31