Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Zeroconf on iOS

Yuji Taniguchi
August 27, 2018
1.2k

Zeroconf on iOS

About overview about the Bonjour.

Yuji Taniguchi

August 27, 2018
Tweet

Transcript

  1. About me • Software Engineer at merpay • Twitter :

    @_natpenguin • GitHub : natpenguin
  2. Zeroconf • To provide IP address • To automatically resolve

    the host name • To automatically distribute the host name • To find services
  3. Protocol AppleTalk Address Resolution Protocol / AppleTalk Address Resolution Protocol

    / Datagram Delivery Protocol /FUXPSL Transport 4FTTJPO 1SFTFOUBUJPO "QQMJDBUJPO Routing Table Maintenance Protocol / AppleTalk Echo Protocol / Name Binding Protocol / AppleTalk Transaction Protocol / AppleTalk Update-Based Routing Protocol AppleTalk Filing Protocol Zone Information Protocol / Printer Access Protocol / AppleTalk Session Protocol / AppleTalk Data Stream Protocol
  4. Bonjour • Instead of AppleTalk • Resolved the problem of

    performance • Implementation on TCP/IP • AirPrint / AirPlay(AirTunes) • Only local network
  5. Bonjour API • To provide IP address • To automatically

    resolve the host name • To automatically distribute the host name • To find services
  6. Bonjour API • To provide IP address • To automatically

    resolve the host name • To automatically distribute the host name • To find services
  7. Server let domain = "local." let type = "_awesome._tcp." let

    name = "Awesome Service" let port: Int32 = 10000
  8. Server let domain = "local." let type = "_awesome._tcp." let

    name = "Awesome Service" let service = NetService(domain: domain, type: type, name: name, port: port) let port: Int32 = 10000
  9. Server let domain = "local." let type = "_awesome._tcp." let

    name = "Awesome Service" service.publish() let service = NetService(domain: domain, type: type, name: name, port: port) let port: Int32 = 10000
  10. Client browser.searchForServices(ofType: type, inDomain: domain) func netServiceBrowser(_ browser: NetServiceBrowser, didFind

    service: NetService, moreComing: Bool) let domain = "local." let type = "_awesome._tcp."
  11. Client browser.searchForServices(ofType: type, inDomain: domain) func netServiceBrowser(_ browser: NetServiceBrowser, didFind

    service: NetService, moreComing: Bool) let domain = "local." let type = "_awesome._tcp." browser.delegate = self
  12. Client extension ViewController: NetServiceBrowserDelegate { func netServiceBrowser(_ browser: NetServiceBrowser, didFind

    service: NetService, moreComing: Bool) { service.resolve(withTimeout: 10.0) } }
  13. Client func netServiceDidResolveAddress(_ sender: NetService) extension ViewController: NetServiceBrowserDelegate { func

    netServiceBrowser(_ browser: NetServiceBrowser, didFind service: NetService, moreComing: Bool) { service.resolve(withTimeout: 10.0) } }
  14. Client func netServiceDidResolveAddress(_ sender: NetService) extension ViewController: NetServiceBrowserDelegate { func

    netServiceBrowser(_ browser: NetServiceBrowser, didFind service: NetService, moreComing: Bool) { service.delegate = self service.resolve(withTimeout: 10.0) } }
  15. Command $ dns-sd -B <Type> $ dns-sd -L <Service Name>

    <Type> <Domain> $ dns-sd -G <protocol> <Hostname> $ dns-sd -H Browsing Resolving a service instance Getting IP Address Help
  16. Command $ dns-sd -B _printer._tcp Browsing a printer service Browsing

    for _printer._tcp DATE: ---Mon 20 Aug 2018--- 3:21:58.151 ...STARTING... Timestamp A/R Flags if Domain Service Type Instance Name 3:21:58.151 Add 2 8 local. _printer._tcp. Printer Service
  17. Network.framework let name = "Awesome Service" let type = "_awesome._tcp."

    let domain = "local." let parameters = NWParameters.tcp let port = NWEndpoint.Port(integerLiteral: 10000) listener.service = NWListener.Service(name: name, type: type, domain: domain) guard let listener = try? NWListener(using: parameters, on: port) else { fatalError("Listener can't be initialized") }