Does Bonjour need a Timer to help it rediscover devices?

I'm using Bonjour, NWListener, NWBrowser, NWConnection, and peer-to-peer to connect devices. Even though I'm not using Mutlipeer, I know that it is built on top of Bonjour and from what I've read the Multipeer range is 20 - 50 meters depending on what's in between the devices etc. For this question I'm assuming that is the same range for these four APIs.

If deviceA is within 50 meters of deviceB, then there will be an automatic discovery/connection. If deviceA moves outside the range to 51 meters, the connection will be lost.

If deviceA moves back within 50 meters, will there be automatic discovery/connection between them again?

The reason I ask is because another developer who has networking experience told me that I have to add a timer to the view controller and fire if off every few seconds so that discovery can keep occurring. I haven't found anything on the forums or stackoverflow that gives any examples of having to use a timer with Bonjour for discovery work. I don't know if I need to add a timer or not to rediscover devices that were once connected, got disconnected, and want to connect again.

I'm far from a Network expert and that is why I ask this question.

Accepted Reply

I haven't found anything on the forums or stackoverflow that gives any
examples of having to use a timer with Bonjour for discovery work.

I strongly recommend against doing that because:
  • Bonjour has complex logic to prevent it from flooding the network traffic. If you start and stop discovery repeatedly, you end up fighting that logic.

  • Bonjour has events for both a service being added and a service being removed, so it’s architected to handle this situation. This supported won’t cover handle all cases perfectly — especially when dealing with peer-to-peer discovery — but that represents a balance between latency and network usage. That balance is one for the OS to make, not your app.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"

Replies

I haven't found anything on the forums or stackoverflow that gives any
examples of having to use a timer with Bonjour for discovery work.

I strongly recommend against doing that because:
  • Bonjour has complex logic to prevent it from flooding the network traffic. If you start and stop discovery repeatedly, you end up fighting that logic.

  • Bonjour has events for both a service being added and a service being removed, so it’s architected to handle this situation. This supported won’t cover handle all cases perfectly — especially when dealing with peer-to-peer discovery — but that represents a balance between latency and network usage. That balance is one for the OS to make, not your app.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
Thanks for the answer! Exactly what I was looking for :)