2

im currently writing an android app, which should keep track of other devices in the same wifi network using JmDNS. The discovery process works correctly, but i don't know how to keep track of other devices especially noticing their removing.

As mentioned in JmDNS device removal detection it seems like i have to implement this callback myself but I dont have any clue how to do this. It seems like the JmDNS Api doesn't provide any method to publish service messages myself.

My ideas so far:

  • Use the discovered socket connection to keep track of changes
  • Use JmDNS.requestServiceInfo() from time to time to check if the service is still available
  • Un-/Register services + listeners so they can find each other again

Does anyone know another way to solve this issue or could tell me how to trigger the serviceRemoved() callback?

PS: before taking this approach I tried Androids-NSD API, which seems to be quite unstable

garfbradaz
  • 3,424
  • 7
  • 43
  • 70
Iconic
  • 41
  • 3

1 Answers1

0

So here are some things i figured out while experimenting:

The DNS-cache is set to one hour, which means that listeners won't remove a service as long as that counter didn't finish.

The mistake i made was unregistering my service after the wifi was switched off. Services send broadcast message that they aren't available anymore. This message can't be sent if the wifi connection was shutdown.

So instead of calling JmDNS.unregisterAllServices() after the wifi connection I have to call it when it's available. This leads to the onServiceRemoved() callback beeing fired in the listener

Iconic
  • 41
  • 3