ZBLOG

15.2.3. Discovery Server During Discovery, the Participant Discovery Phase (PDP) relies on meta traffic announcements sent to multicast addresses so that all the DomainParticipants in the network can acknowledge each other. This phase is followed...

15.2.3. Discovery Server

在发现阶段,参与者发现阶段(PDP)依赖于发送到多播地址的元流量公告,以便网络中的所有DomainParticipants能够彼此确认。这一阶段之后是端点发现阶段(EDP),所有DomainParticipants使用发现的单播地址交换关于其发布者和订阅者实体的信息,以便可以进行同一主题实体之间的匹配。

Fast DDS提供了一种客户端-服务器发现机制,其中一个服务器DomainParticipant作为通信的中心点。它收集和处理来自客户端DomainParticipants发送的元流量,然后将适当的信息分发给其他客户端。

有关该功能的完整描述,请参见《Discovery Server Settings》。以下小节展示了不同发现服务器用例的配置。

UDPv4基本示例设置

要配置Discovery Server场景,需要创建两种类型的参与者:服务器参与者和客户端参与者。在这种实现中,只需配置一个参数:

  • 服务器地址-端口对:指定实现服务器的机器的IP地址和端口。可以使用任何空闲随机端口,但不建议使用RTPS标准端口。

SERVER 配置示例

C++ 示例代码
DomainParticipantQos qos;

// 将当前参与者配置为 SERVER
qos.wire_protocol().builtin.discovery_config.discoveryProtocol = DiscoveryProtocol::SERVER;

// 定义在接口192.168.10.57和端口56542上监听定位器
Locator_t server_locator;
IPLocator::setIPv4(server_locator, "192.168.10.57");
server_locator.port = 56542;
qos.wire_protocol().builtin.metatrafficUnicastLocatorList.push_back(server_locator);
XML 配置示例
<?xml version="1.0" encoding="UTF-8" ?>
<profiles xmlns="http://www.eprosima.com">
    <participant profile_name="discovery_server_profile" is_default_profile="false">
        <rtps>
            <builtin>
                <discoveryConfig>
                    <discoveryProtocol>SERVER</discoveryProtocol>
                </discoveryConfig>
                <!-- 定义服务定位器 -->
                <metatrafficUnicastLocatorList>
                    <locator>
                        <udpv4>
                            <address>192.168.10.57</address>
                            <port>56542</port>
                        </udpv4>
                    </locator>
                </metatrafficUnicastLocatorList>
            </builtin>
        </rtps>
    </participant>
</profiles>

CLIENT 配置示例

C++ 示例代码
DomainParticipantQos qos;

// 将当前参与者配置为 CLIENT
qos.wire_protocol().builtin.discovery_config.discoveryProtocol = DiscoveryProtocol::CLIENT;

// 定义指向 SERVER Participant 的定位器,地址为192.168.10.57,端口为56542
Locator_t remote_server_locator;
IPLocator::setIPv4(remote_server_locator, "192.168.10.57");
remote_server_locator.port = 56542;

// 连接到之前定义的SERVER定位器
qos.wire_protocol().builtin.discovery_config.m_DiscoveryServers.push_back(remote_server_locator);
XML 配置示例
<?xml version="1.0" encoding="UTF-8" ?>
<profiles xmlns="http://www.eprosima.com">
    <participant profile_name="discovery_client_profile" is_default_profile="false">
        <rtps>
            <builtin>
                <discoveryConfig>
                    <discoveryProtocol>CLIENT</discoveryProtocol>
                    <!-- 指定与 SERVER 的连接 -->
                    <m_DiscoveryServers> 
                        <locator> 
                            <udpv4> 
                                <address>192.168.10.57</address> 
                                <port>56542</port> 
                            </udpv4> 
                        </locator> 
                    </m_DiscoveryServers> 
                </discoveryConfig>
            </builtin>
        </rtps>
    </participant>
</profiles>

总结

以上代码段和XML配置展示了如何设置Discovery Server及其客户端。通过设置特定的IP地址和端口,可以确保多个DomainParticipants能够正确地找到并交互。这种方法提高了系统内各个组件之间的通信效率,同时简化了网络拓扑管理。


内容由零声教学AI助手提供,问题来源于学员提问

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:http://sdn.0voice.com/?id=7488

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?