Bluetooth/Wifi connections

This isn’t really Xojo related, although I’m sure that someone is/has or will delve into this subject if not already…

I am playing with Apples MultipeerConnectivity, and have most everything working… but I’d like to know which device was the first to start the app.

Here is the flow as best I can tell…

  • Device A starts up the app… it adds its connection info to an internal dictionary, and waits
  • Device A advertises its existence… gets no response
  • Device B starts up the app… and it add its connection (remember the dictionary are local to each device)
  • Device B advertises its existence and Device A invites it to the party, and both devices add the other to their respective dictionary

at first I thought I could go by, if it were the first entry into an empty dictionary… but each device ends up first in its own
plus if there are a dozen devices, and whoever was “first” goes away, another device needs to take its place…

A Master/Slave arrangement for lack of a more politically correct description.

It is to insure that only one person in the “network” can perform certain “admin” events. Since its BT, everyone will most likely be in the same room, but the app requires a “master” active at all times, even if its the only device running.

If this was an Ethernet network I would possibly do something like this:
• Make all of the devices part of a multicast UDP group so they can broadcast their presence to each other on a regular interval. This would then allow each device to hold a list of other devices. A device could then remove other devices from its own internal list if it hadn’t received a message within a certain time frame.

• This would then leave the challenge of determining who was the master. If the devices were synchronised to the same time source (ie: a network time server) they could also send the time the app was started up when they broadcasted (maybe use microseconds to help avoid collisions). The master would then be the device in the list which had the earliest startup time.