Bonjour, also known as zero-configuration networking, enables automatic discovery of devices and services on a local network using industry standard.

Posts under Bonjour tag

167 Posts

Post

Replies

Boosts

Views

Activity

Bonjour discovery with NetServiceBrowser not working in iOS and iPadOS 14
My app has to find a certain bonjour service on the local network and my code works fine for iOS 12/13 as well as macOS Big Sur and Catalina. The exact same code fails on iOS and iPadOS 14 with this error: ["NSNetServicesErrorDomain": 10, "NSNetServicesErrorCode": -72000] Which I have looked into and -72000 is an "Unknown error". I am using NetServiceBrowser to find the service and here is my code: class Bonjour: NSObject {     var discovered: [DiscoveredInstance] = []     let bonjourBrowser = NetServiceBrowser()     var discoveredService: NetService?     override init() {         super.init()         bonjourBrowser.delegate = self         startDiscovery()     }     func startDiscovery() {         self.bonjourBrowser.searchForServices(ofType: "_some-service._tcp.", inDomain: "local")     } } extension Bonjour: NetServiceBrowserDelegate, NetServiceDelegate {     func netServiceBrowser(_ browser: NetServiceBrowser, didFind service: NetService, moreComing: Bool) {         discoveredService = service         discoveredService?.delegate = self         discoveredService?.resolve(withTimeout: 3)     }     func netServiceBrowser(_ browser: NetServiceBrowser, didNotSearch errorDict: [String : NSNumber]) {         print(errorDict)     }     func netServiceBrowser(_ browser: NetServiceBrowser, didRemove service: NetService, moreComing: Bool) {         self.discovered.removeAll { $0.name == service.name }     }     func netServiceDidResolveAddress(_ sender: NetService) {         if let data = sender.txtRecordData() {             let dict = NetService.dictionary(fromTXTRecord: data)             /// do stuff with txtRecord dict here and then add to discovered array.             discoveredService = nil         }     } } I have no idea what could be causing the error and have tried enabling networking permissions and capabilities but have not been able to stop the error from occurring. Thanks.
8
1
13k
Nov ’21
iOS 15 Local Network permission issue
Hello, Our app (OceanDMX Colours) can't communicate with their device over the network, because Local Network access is not applied in the iOS15 Settings. It does not ask about permission when installing and does not show in the Settings App -> Privacy -> Local Network. Was working fine until the release of the iOS 15. We did multiple tests and it works fine with older version of iOS (14.8), when installing it ask for permission and shows up in Settings App -> Privacy -> Local Network with the toggle option. Any ideas how to solve this issue? Has anyone run into the same problem?
1
0
3.4k
Nov ’21
Bonjour stopped responding in iOS15
My company's app uses the following code to look for services advertised by a Garmin VIRB 360 camera (now discontinued and unsupported). In the past this code has worked fine. However, on my iPhone 12 Pro Max running iOS 15.0.2 it returns no services. let serviceBrowser = NetServiceBrowser() serviceBrowser.searchForServices(ofType: "_garmin-virb._tcp.", inDomain: "local.") Did something change in iOS 15? Do I need some entitlement? Is the format of the strings incorrect? My recollection is that the strings are from Garmin document (but its years old). Any help greatly appreciated!
3
0
1.3k
Oct ’21
Receiving UDP/5353 packets in iOS app
Hello, I am trying to write an iOS app which could receive and analyze mDNS queries. More specifically, I have my app register a Bonjour service, and I need to see queries from the network for any subtype of my primary type, although I have not registered any subtype myself. Reason being that I have a device that tries to find me using a specific primary type, but always includes a subtype in its queries, and I can't know the subtype in advance, so I can't register my service with the subtype. So I'd need to see the query, extract the subtype and re-register my service with that subtype so that the device can then find me. Looks like the various APIs to interact with Bonjour won't let me do that. I've tried another approach and started a NWListener on port 5353 with allowLocalEndpointReuse set to true, but I'm getting "Address already in use" and it doesn't work, since this port is likely to be used by the mDNSresponder service. Is there an API I could use to achieve what I described above ?
2
0
1.8k
Oct ’21
NEDNSProxyProvider: network troubles on iOS 14
Hello everyone. I made a minimal example with DNS proxy. It works well on iOS 12, and doesn't work on iOS 14 (proxy runs well, but websites don't load). Traffic on iOS 14: 2 DNS queries (type A and type 65) + 2 successful DNS responses and it's all (there are no more IP packets). DoH / DoT are disabled. In logs everything is OK (no errors, everywhere are the same number of packets (read from NEAppProxyUDPFlow = sent to NWConnection = received from NWConnection = written to NEAppProxyUDPFlow). There are no TCP connections. Thanks in advance for any ideas / suggestions. import NetworkExtension //import DNS class DNSProxyProvider: NEDNSProxyProvider {       override init() {     super.init()   }   override func startProxy(options: [String: Any]? = nil,                completionHandler: @escaping (Error?) -> Void) {     completionHandler(nil)   }   override func stopProxy(with reason: NEProviderStopReason,               completionHandler: @escaping () -> Void) {     completionHandler()   }   override func sleep(completionHandler: @escaping () -> Void) {     completionHandler()   }   override func wake() {}       override func handleNewFlow(_ flow: NEAppProxyFlow) -> Bool {     if let tcpFlow = flow as? NEAppProxyTCPFlow {       NSLog("MyDebug: TCP connection")     } else if let udpFlow = flow as? NEAppProxyUDPFlow {       NSLog("MyDebug: UDP connection")       establishConnection(flow: udpFlow)       openFlow(flow: udpFlow)     }     return true   }   private func openFlow(flow: NEAppProxyUDPFlow) {     flow.open(withLocalEndpoint: nil) { opnErr in       if let e = opnErr {         NSLog("MyDebug: open error - \(e.localizedDescription)")       } else {         NSLog("MyDebug: open - ok")       }     }   }       private func establishConnection(flow: NEAppProxyUDPFlow) {     let conn = NWConnection(host: "8.8.8.8", port: 53, using: .udp)     conn.stateUpdateHandler = { state in       switch state {       case .ready:         NSLog("MyDebug: establishConnection ready")         self.send(flow: flow, connection: conn)       case .setup:         NSLog("MyDebug: establishConnection setup")       case .cancelled:         NSLog("MyDebug: establishConnection cancelled")       case .preparing:         NSLog("MyDebug: establishConnection preparing")       default:         NSLog("MyDebug: establishConnection default")       }     }     conn.start(queue: .global())   }       private func send(flow: NEAppProxyUDPFlow,            connection conn: NWConnection) {     flow.readDatagrams { (datagrams, endpoints, rdErr) in       let datas = self.extractReadData(rdErr: rdErr, datagrams: datagrams)       for packet in datas {         conn.send(content: packet,              completion: .contentProcessed( { sndErr in               if let e = sndErr {                 NSLog("MyDebug: send error - \(e.localizedDescription)")               } else {                 NSLog("MyDebug: send - ok")                 self.receive(flow: flow, connection: conn)               }         }))       }     }   }       private func extractReadData(rdErr: Error?,                  datagrams: [Data]?) -> [Data] {     if rdErr == nil, let datas = datagrams, !datas.isEmpty {       NSLog("MyDebug: read - ok")       return datas     } else {       if let e = rdErr {         NSLog("MyDebug: read error - \(e.localizedDescription)")       } else {         NSLog("MyDebug: read - datagrams is empty or null")       }       return []     }   }       private func receive(flow: NEAppProxyUDPFlow,              connection conn: NWConnection) {     conn.receiveMessage { (data, context, isComplete, rcvErr) in       let d = self.extractReceivedData(data: data, isComplete: isComplete, rcvErr: rcvErr)               flow.writeDatagrams([d], sentBy: [flow.localEndpoint!]) { wrtErr in         if let e = wrtErr {           NSLog("MyDebug: write error - \(e.localizedDescription)")         } else {           NSLog("MyDebug: write - ok")         }       }     }   }       private func extractReceivedData(data: Data?,                    isComplete: Bool,                    rcvErr: NWError?) -> Data {     if isComplete, rcvErr == nil, let d = data {       NSLog("MyDebug: receive - ok")       return d     } else {       if let e = rcvErr {         NSLog("MyDebug: receive error - \(e.localizedDescription)")       } else {         NSLog("MyDebug: receive - isComplete = \(isComplete); data = \(data)")       }       return Data()     }   } }
3
0
1.2k
Sep ’21
Bonjour discovery with NetServiceBrowser not working in iOS and iPadOS 14
My app has to find a certain bonjour service on the local network and my code works fine for iOS 12/13 as well as macOS Big Sur and Catalina. The exact same code fails on iOS and iPadOS 14 with this error: ["NSNetServicesErrorDomain": 10, "NSNetServicesErrorCode": -72000] Which I have looked into and -72000 is an "Unknown error". I am using NetServiceBrowser to find the service and here is my code: class Bonjour: NSObject {     var discovered: [DiscoveredInstance] = []     let bonjourBrowser = NetServiceBrowser()     var discoveredService: NetService?     override init() {         super.init()         bonjourBrowser.delegate = self         startDiscovery()     }     func startDiscovery() {         self.bonjourBrowser.searchForServices(ofType: "_some-service._tcp.", inDomain: "local")     } } extension Bonjour: NetServiceBrowserDelegate, NetServiceDelegate {     func netServiceBrowser(_ browser: NetServiceBrowser, didFind service: NetService, moreComing: Bool) {         discoveredService = service         discoveredService?.delegate = self         discoveredService?.resolve(withTimeout: 3)     }     func netServiceBrowser(_ browser: NetServiceBrowser, didNotSearch errorDict: [String : NSNumber]) {         print(errorDict)     }     func netServiceBrowser(_ browser: NetServiceBrowser, didRemove service: NetService, moreComing: Bool) {         self.discovered.removeAll { $0.name == service.name }     }     func netServiceDidResolveAddress(_ sender: NetService) {         if let data = sender.txtRecordData() {             let dict = NetService.dictionary(fromTXTRecord: data)             /// do stuff with txtRecord dict here and then add to discovered array.             discoveredService = nil         }     } } I have no idea what could be causing the error and have tried enabling networking permissions and capabilities but have not been able to stop the error from occurring. Thanks.
Replies
8
Boosts
1
Views
13k
Activity
Nov ’21
iOS 15 Local Network permission issue
Hello, Our app (OceanDMX Colours) can't communicate with their device over the network, because Local Network access is not applied in the iOS15 Settings. It does not ask about permission when installing and does not show in the Settings App -> Privacy -> Local Network. Was working fine until the release of the iOS 15. We did multiple tests and it works fine with older version of iOS (14.8), when installing it ask for permission and shows up in Settings App -> Privacy -> Local Network with the toggle option. Any ideas how to solve this issue? Has anyone run into the same problem?
Replies
1
Boosts
0
Views
3.4k
Activity
Nov ’21
Bonjour stopped responding in iOS15
My company's app uses the following code to look for services advertised by a Garmin VIRB 360 camera (now discontinued and unsupported). In the past this code has worked fine. However, on my iPhone 12 Pro Max running iOS 15.0.2 it returns no services. let serviceBrowser = NetServiceBrowser() serviceBrowser.searchForServices(ofType: "_garmin-virb._tcp.", inDomain: "local.") Did something change in iOS 15? Do I need some entitlement? Is the format of the strings incorrect? My recollection is that the strings are from Garmin document (but its years old). Any help greatly appreciated!
Replies
3
Boosts
0
Views
1.3k
Activity
Oct ’21
mirror.dca.local - which Bonjour service ?
Hi Does anyone know what the Bonjour service that advertises mirror.dca.local is used for ? I upgraded from 14.4 to 14.7.1 and see that my phone is broadcasting this using multicastDNS / Bonjour. Merci beaucoup
Replies
0
Boosts
0
Views
481
Activity
Oct ’21
Network framework send file using TCP protocol
I am able to send json data between NWConnection and NW Listener. I need help to send photo or any file to each other. I am using TCP protocol for data transfer. Please let me know how can I send any file. Thank You
Replies
4
Boosts
0
Views
1.4k
Activity
Oct ’21
Receiving UDP/5353 packets in iOS app
Hello, I am trying to write an iOS app which could receive and analyze mDNS queries. More specifically, I have my app register a Bonjour service, and I need to see queries from the network for any subtype of my primary type, although I have not registered any subtype myself. Reason being that I have a device that tries to find me using a specific primary type, but always includes a subtype in its queries, and I can't know the subtype in advance, so I can't register my service with the subtype. So I'd need to see the query, extract the subtype and re-register my service with that subtype so that the device can then find me. Looks like the various APIs to interact with Bonjour won't let me do that. I've tried another approach and started a NWListener on port 5353 with allowLocalEndpointReuse set to true, but I'm getting "Address already in use" and it doesn't work, since this port is likely to be used by the mDNSresponder service. Is there an API I could use to achieve what I described above ?
Replies
2
Boosts
0
Views
1.8k
Activity
Oct ’21
NEDNSProxyProvider: network troubles on iOS 14
Hello everyone. I made a minimal example with DNS proxy. It works well on iOS 12, and doesn't work on iOS 14 (proxy runs well, but websites don't load). Traffic on iOS 14: 2 DNS queries (type A and type 65) + 2 successful DNS responses and it's all (there are no more IP packets). DoH / DoT are disabled. In logs everything is OK (no errors, everywhere are the same number of packets (read from NEAppProxyUDPFlow = sent to NWConnection = received from NWConnection = written to NEAppProxyUDPFlow). There are no TCP connections. Thanks in advance for any ideas / suggestions. import NetworkExtension //import DNS class DNSProxyProvider: NEDNSProxyProvider {       override init() {     super.init()   }   override func startProxy(options: [String: Any]? = nil,                completionHandler: @escaping (Error?) -> Void) {     completionHandler(nil)   }   override func stopProxy(with reason: NEProviderStopReason,               completionHandler: @escaping () -> Void) {     completionHandler()   }   override func sleep(completionHandler: @escaping () -> Void) {     completionHandler()   }   override func wake() {}       override func handleNewFlow(_ flow: NEAppProxyFlow) -> Bool {     if let tcpFlow = flow as? NEAppProxyTCPFlow {       NSLog("MyDebug: TCP connection")     } else if let udpFlow = flow as? NEAppProxyUDPFlow {       NSLog("MyDebug: UDP connection")       establishConnection(flow: udpFlow)       openFlow(flow: udpFlow)     }     return true   }   private func openFlow(flow: NEAppProxyUDPFlow) {     flow.open(withLocalEndpoint: nil) { opnErr in       if let e = opnErr {         NSLog("MyDebug: open error - \(e.localizedDescription)")       } else {         NSLog("MyDebug: open - ok")       }     }   }       private func establishConnection(flow: NEAppProxyUDPFlow) {     let conn = NWConnection(host: "8.8.8.8", port: 53, using: .udp)     conn.stateUpdateHandler = { state in       switch state {       case .ready:         NSLog("MyDebug: establishConnection ready")         self.send(flow: flow, connection: conn)       case .setup:         NSLog("MyDebug: establishConnection setup")       case .cancelled:         NSLog("MyDebug: establishConnection cancelled")       case .preparing:         NSLog("MyDebug: establishConnection preparing")       default:         NSLog("MyDebug: establishConnection default")       }     }     conn.start(queue: .global())   }       private func send(flow: NEAppProxyUDPFlow,            connection conn: NWConnection) {     flow.readDatagrams { (datagrams, endpoints, rdErr) in       let datas = self.extractReadData(rdErr: rdErr, datagrams: datagrams)       for packet in datas {         conn.send(content: packet,              completion: .contentProcessed( { sndErr in               if let e = sndErr {                 NSLog("MyDebug: send error - \(e.localizedDescription)")               } else {                 NSLog("MyDebug: send - ok")                 self.receive(flow: flow, connection: conn)               }         }))       }     }   }       private func extractReadData(rdErr: Error?,                  datagrams: [Data]?) -> [Data] {     if rdErr == nil, let datas = datagrams, !datas.isEmpty {       NSLog("MyDebug: read - ok")       return datas     } else {       if let e = rdErr {         NSLog("MyDebug: read error - \(e.localizedDescription)")       } else {         NSLog("MyDebug: read - datagrams is empty or null")       }       return []     }   }       private func receive(flow: NEAppProxyUDPFlow,              connection conn: NWConnection) {     conn.receiveMessage { (data, context, isComplete, rcvErr) in       let d = self.extractReceivedData(data: data, isComplete: isComplete, rcvErr: rcvErr)               flow.writeDatagrams([d], sentBy: [flow.localEndpoint!]) { wrtErr in         if let e = wrtErr {           NSLog("MyDebug: write error - \(e.localizedDescription)")         } else {           NSLog("MyDebug: write - ok")         }       }     }   }       private func extractReceivedData(data: Data?,                    isComplete: Bool,                    rcvErr: NWError?) -> Data {     if isComplete, rcvErr == nil, let d = data {       NSLog("MyDebug: receive - ok")       return d     } else {       if let e = rcvErr {         NSLog("MyDebug: receive error - \(e.localizedDescription)")       } else {         NSLog("MyDebug: receive - isComplete = \(isComplete); data = \(data)")       }       return Data()     }   } }
Replies
3
Boosts
0
Views
1.2k
Activity
Sep ’21