How can I identify different participants in the same network?

3 posts / 0 new
Last post
Offline
Last seen: 8 years 6 months ago
Joined: 01/04/2015
Posts: 6
How can I identify different participants in the same network?

Hi everyone,

I have a question and hope you can help me. I am learning to use DDS so forgive my mistakes.

I am running a game and I have 3 players who are exchanging their position among them (the three players run on the same machine but each one is associated with an execution of the program). How could I identify each of them? I mean, I need to know the participant (or publisher? I am not sure) which corresponding to each player. Could I use the "participation_handle" (according to the API  "Identifies locally the DataWriter that modified the instance")? And could I know the "partipation_handle" associated with a publisher when a message is sent?

Another way to do the identification is by sending an identifier (a number) in the messages of each player, but the problem is that I must first receive several messages to know the ID of the other players to not use an existing ID. Is there any function or process that simplifies this?

I attached a picture with the situation.

Thank you in advance.

 

AttachmentSize
Image icon Diagram23.43 KB
Offline
Last seen: 10 months 2 weeks ago
Joined: 02/11/2016
Posts: 144

Hey, FranSoriano.

Firstly, DDS is by nature an anonymous pubsub protocol.

That being said, there are multiple ways of identifying the source of data:

1. participant handle is one of them

2. writer guid is another

3. there may be others

Secondly, I would recommend using a guid / uuid (there are functions that will generate those) instead of using a running number.

Surely that will increase the size of the id and will also take a bit of time to create, but it will spare you the headache of synching the players when they assign ids.

It should be noted that there exists some minute chance that using uuid will result in a collision.

 

Hopefully this helped.

Gerardo Pardo's picture
Offline
Last seen: 3 weeks 3 days ago
Joined: 06/02/2010
Posts: 602

Hello,

If the identity of the "Player" is an important part of the application, then you can include this information as part of the data that the player sends. For example include a "player_name" string field in the IDL definition of the data the player is sending. 

Alternatively if each DataWriter or DomainPartcicipant represents only one player you can put encode that into the publication_name attribute that appears in the DataWriterQos.

When you get a Sample you can use the DataReader::get_matched_publication_data() to retrieve information about the DatataWriter thet sent the data. You will get the PublicationBultinTopicData which contains all the information including the publication_name that you assigned to the DataWriter.

Also note that the publication_handle that appears in the SampleInfo associated with the data contains a unique identifier (GUID) for the DataWriter that wrote the sample.

Gerardo