How do I set the initial peers and multicast receive address programmatically or via XML?

Note: Relevant versions RTI Connext 4.x and above.

Method One: setting the initial peers and multicast receive address programmatically (applies to all 4.x versions and above)

The following C++ code snippet shows how to configure the initial peers and multicast receive address programmatically (rather than via NDDS_DISCOVERY_PEERS environmental variable or via a file):
  DDS_DomainParticipantQos participant_qos;

  /* To customize participant QoS for peer host */
  DDSTheParticipantFactory->get_default_participant_qos(participant_qos);

  /* free original memory */
  participant_qos.discovery.initial_peers.maximum(0);

  /* set new initial peer for sending discovery information  */
  participant_qos.discovery.initial_peers.maximum(3);
  participant_qos.discovery.initial_peers.length(3);
  participant_qos.discovery.initial_peers[0] = DDS_String_dup("239.255.0.1");
  participant_qos.discovery.initial_peers[1] = DDS_String_dup("4@builtin.udpv4://127.0.0.1");
  participant_qos.discovery.initial_peers[2] = DDS_String_dup("builtin.shmem://");

  /* free original memory */
  participant_qos.discovery.multicast_receive_addresses.maximum(0);

  /* set new multicast receive address for receiving multicast
     discovery information */
  participant_qos.discovery.multicast_receive_addresses.maximum(1);
  participant_qos.discovery.multicast_receive_addresses.length(1);
  participant_qos.discovery.multicast_receive_addresses[0] =    DDS_String_dup("239.255.0.1");

  participant = DDSTheParticipantFactory->create_participant(
      domainId, participant_qos, 
      NULL /* listener */, DDS_STATUS_MASK_NONE);

  if (participant == NULL) {
      printf("create_participant error\n");
      subscriber_shutdown(participant, subscriber, topic, reader);
      return -1;
  } 


The following snippet shows how to set initial peers and multicast receive address in C:

 struct DDS_DomainParticipantQos participant_qos = DDS_DomainParticipantQos_INITIALIZER;
 DDS_DomainParticipantFactory *factory_ptr = DDS_DomainParticipantFactory_get_instance();
    
 retcode = DDS_DomainParticipantFactory_get_default_participant_qos(factory_ptr,&participant_qos);
 if (retcode != DDS_RETCODE_OK) {
    printf("get_default_participant_qos error\n");
    return -1;
 }  

 /* set new initial peer for sending discovery information  */
 DDS_StringSeq_set_maximum(&participant_qos.discovery.initial_peers,3); 
 DDS_StringSeq_set_length(&participant_qos.discovery.initial_peers,3); 

 *DDS_StringSeq_get_reference(&participant_qos.discovery.initial_peers,0) = DDS_String_dup("239.255.0.1"); 
 *DDS_StringSeq_get_reference(&participant_qos.discovery.initial_peers,1) = DDS_String_dup("4@builtin.udpv4://127.0.0.1");
 *DDS_StringSeq_get_reference(&participant_qos.discovery.initial_peers,2) = DDS_String_dup("builtin.shmem://");  

 /* set new multicast receive address for receiving multicast discovery information */
 DDS_StringSeq_set_maximum(&participant_qos.discovery.multicast_receive_addresses,1); 
 DDS_StringSeq_set_length(&participant_qos.discovery.multicast_receive_addresses,1); 

 *DDS_StringSeq_get_reference(&participant_qos.discovery.multicast_receive_addresses,0) = DDS_String_dup("239.255.0.1"); 

 participant = DDS_DomainParticipantFactory_create_participant(
     DDS_TheParticipantFactory, domainId, &participant_qos,
     NULL /* listener */, DDS_STATUS_MASK_NONE);
 if (participant == NULL) {
     printf("create_participant error\n");
     subscriber_shutdown(participant);
     return -1;
 }

 

Method Two: setting the initial peers and multicast receive address via XML (applies to version 4.3 and higher)

This method uses an XML QoS profile to configure the DomainParticipant initial peers and multicast receive address.

<dds>
    <qos_library name="InitialPeersMulticastReceiveAddressLibrary">
        <qos_profile name="DefaultProfile">
            <participant_qos>                
                <discovery>
                    <initial_peers>
                        <element>239.255.0.1</element>
                        <element>4@builtin.udpv4://127.0.0.1</element>
                        <element>builtin.shmem://</element>
                    </initial_peers>
                    <multicast_receive_addresses>
                        <element>239.255.0.1</element>
                    </multicast_receive_addresses>
                </discovery>
            </participant_qos>
        </qos_profile>
    </qos_library>
</dds>

If you are using RTI Data Distribution Service 4.3e, you must call  DDSTheParticipantFactory->load_profiles() before creating the DomainParticipant with a profile.

When using RTI Data Distribution Service 4.4 and higher, the XML file can be automatically loaded. If NDDS_QOS_PROFILES.xml is in the $NDDSHOME/resource/xml directory, it will be automatically loaded. Similarly, if USER_QOS_PROFILES.xml is in the working directory, it will be automatically loaded. See the RTI Core Libraries and Utilities User’s Manual for more details on XML file loading.

When using RTI Data Distribution Service 4.4 and higher, place the attached USER_QOS_PROFILES.xml file in the working directory. It specifies InitialPeersMulticastReceiveAddressLibrary as the default QoS profile and will be loaded when your DDS application starts.

Comments

Is there a C code to program the initial peers and multicast receive address?

Thanks

JN