java data reader using multicast

2 posts / 0 new
Last post
Offline
Last seen: 2 years 11 months ago
Joined: 02/02/2015
Posts: 6
java data reader using multicast

Hi,

I've seen the examples of how to set up a reader_qos for multicast in C++.

Sadly, I couldnt easily translate this to work in java.

is there an example of this anywhere or can anyone share?

I assume it's only 1 or 2 lines of code in the reader_qos to add the address?

 

Fernando Garcia's picture
Offline
Last seen: 2 months 3 weeks ago
Joined: 05/18/2011
Posts: 200

Hi lmc_aaron,

You can specify the reader's multicast address either programatically:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// ...
// Get Default Reader's QoS and modify it before creating
// the actual reader.
DataReaderQos reader_qos = new DataReaderQos();
subscriber.get_default_datareader_qos(reader_qos);
  
// Configure multicast settings and update the Reader's QoS
// accordingly
TransportMulticastSettings_t multicastSettings =
    new TransportMulticastSettings_t();
multicastSettings.receive_address = InetAddress.getByName("239.255.1.2");
multicastSettings.receive_port = 3456;
  
reader_qos.multicast.value.add(multicastSettings);
reader_qos.multicast.kind =
    TransportMulticastQosPolicyKind.AUTOMATIC_TRANSPORT_MULTICAST_QOS;
  
// Create DataReader with modified QoS
reader = (HelloWorldDataReader) subscriber.create_datareader(
    topic, reader_qos, listener,
    StatusKind.STATUS_MASK_ALL);
if (reader == null) {
    System.err.println("create_datareader error\n");
    return;
}
// ...
or via XML:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<dds>
   <qos_library name="MulticastTTLLibrary">
       <qos_profile name="DefaultProfile">
           <datareader_qos>
               <multicast>
                   <value>
                       <element>
                           <receive_address>239.255.1.2</receive_address>
                           <receive_port>3456</receive_address>
                       </element>
                   </value>
                  <kind>AUTOMATIC_TRANSPORT_MULTICAST_QOS</kind>
               </multicast>
           </datareader_qos>
       </qos_profile>
   </qos_library>
</dds>

Thanks,
Fernando.