Thank you for your reply. the failure I am seeing is a bit deeper in the process, not with the NWBrowser, but with the NWConnection I am ultimately using to resolve the ipaddress.
Below, you will see my extra code that I added to the sample you provided above. I use the changes to create a NWConnection
Is there a simpler way to get the ipaddress?
self.browser.browseResultsChangedHandler = { services, changes in
self.services = services.map { result in
guard case .service(name: let name, type: _, domain: _, interface: let interface) = result.endpoint else { fatalError() }
return Service(name: name, endpoint: result.endpoint, interface: interface, connection: nil)
}
print("SERVICES \(self.services)")
for change in changes {
if case .added(let added) = change {
switch added.endpoint {
case .service(name: let name, type: let type, domain: let domain, interface: let interface):
self.netConnection = NWConnection(to: .service(name: name, type: type, domain: domain, interface: interface), using: .tcp)
print("netConnection stateUpdateHandler start")
self.netConnection?.stateUpdateHandler = { (newState) in
//with _ssh._tcp. this new state below never gets past `preparing`. With the other type, it goes to `ready` then I get the host
print("netConnection newState \(newState)")
switch (newState) {
case .ready:
guard let currentPath = self.netConnection?.currentPath else { return }
if let endpoint = currentPath.remoteEndpoint {
switch endpoint {
case .hostPort(host: let host, port: _):
switch host {
case .ipv4(_):
//this is where I get the ipaddress ...
print("host ipv4: \(host.debugDescription)")
case .ipv6(_):
//this is where I get the ipaddress ...
print("host ipv6: \(host.debugDescription)")
default:
print("host: not found")
break
}
default:
break
}
}
default:
break
}
}
default:
break
}
}
}
self.netConnection?.start(queue: .main)