Echo Messages

5 posts / 0 new
Last post
Offline
Last seen: 7 years 11 months ago
Joined: 03/29/2016
Posts: 3
Echo Messages

Hi there,


I was wondering if there is any way to have a message sent back and forth between two computers on the same network, that is if computer 1 sends a data message to computer 2, and computer 2 changes some of the data, and sends it back to computer 1. Is this only possible with request/reply?

Thanks!

Keywords:
Offline
Last seen: 2 months 2 weeks ago
Joined: 02/11/2016
Posts: 144

Hey,

Surely you can write some code that utilizes a reader and a writer on both computers, where both readers and both writers are using the same topic to communicate back and forth. In this case you may want to use a filter so that messages sent by a writer on computer A won't be handled by the reader on computer A (and similarly for computer B).

Another simple approach which doesn't require the request/reply api is to simulate a request/reply pattern:

Define two topics AtoB and BtoA and use those (over the same type, if I understand your scenario correctly).

 

Hopefully this helps you, if not please elaborate why it doesn't.

 

Roy.

Offline
Last seen: 7 years 11 months ago
Joined: 03/29/2016
Posts: 3

Thank you! But I think I should elaborate more. I'm basing my program off of the Hello IDL example, and the problem I'm running into is I'm using the DDS function on_data_received, part of class hello_listener. What I'm trying to do is when the on_data_received function is called, and the subsequent process_data class function is called, a function "sendData" is called, which will write to a new topic. The problem I'm encountering is I can't create a new participant to create a new topic inside the class functions since it I "can't create a participant in a callback", and I can't send the class function the ponter to the same participant to create the necessary entities to send the message. The end goal is to return a message from machine b as soon as a message comes into machine b. If you have any ideas on how to send a pointer to the participant to the listener, or any other methods to forward a message as soon as it comes i'd love to hear them . Thank you for your suggestions though

 

Gerardo Pardo's picture
Offline
Last seen: 9 hours 29 min ago
Joined: 06/02/2010
Posts: 601

Hi,

I see... In general you should not be creating DDS entities: DomainParticipants, Topics, DataWriters, DataReaders each time you want to send a messages. And certainly not inside callbacks. DDS Entities are expensive resources: They allocate significant memory, create several threads (in the case of a DomainParticipant), and need to be discovered network wide. This is described in the DDS best practices at https://community.rti.com/best-practices take a look at those and specifically this one: https://community.rti.com/best-practices/create-and-delete-dds-entities-outside-write-or-read-loop

Since you should be using a single DomainParticipant in your scenario (the same one for the DataReader and the DataWriter), all you need to do is pre-create the reply Topic and DataWriter before you install the DataReaderListener and then pass that DataWriter as a parameter when you register the DataReaderListener. Within the DataReaderListener you can just call "write" on the DataWriter to send the reply back.

There us a "latecy benchmark" example in your installation that does this altthough it is probably more complex than what you are looking for. It can be found under examples/connext_dds/c++/performance/latency

Gerardo

Offline
Last seen: 7 years 11 months ago
Joined: 03/29/2016
Posts: 3

Tahnk you very much, that's exactly what I was looking for. I really appreciate your help, have a good one!