I am using NWBrowser to detect SignalK servers on a network using the following Swift code:
let browser = NWBrowser(for: .bonjourWithTXTRecord(type: "_http._tcp", domain: nil), using: NWParameters())
browser.browseResultsChangedHandler = { results, changes in
print("Found \(results.count) results and \(changes.count) changes")
}
When this is run on a network with 5 devices then the output is often
Found 5 results and 5 changes
But, sometime it is:
Found 2 results and 2 changes
Found 5 results and 3 changes
indicating that the browseResultsChangedHandler is being called more than once.
So my question is how do I determine when the browsing process has finished (obviously without the knowledge that there are 5 devices)?
The depreciated NetServiceBrowser had a delegate method (netServiceBrowser(_:didFind:moreComing:) but I can't see an equivalent for NWBrowser.
The only method I can think of is to apply a short time out.