Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Zeroconf on iOS
Search
Yuji Taniguchi
August 27, 2018
2
1.3k
Zeroconf on iOS
About overview about the Bonjour.
Yuji Taniguchi
August 27, 2018
Tweet
Share
More Decks by Yuji Taniguchi
See All by Yuji Taniguchi
Zero Configuration
natpenguin
1
230
The ownership in iOS
natpenguin
0
360
Featured
See All Featured
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
49
9.9k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
61k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
430
Scaling GitHub
holman
464
140k
Darren the Foodie - Storyboard
khoart
PRO
2
2.4k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
250
Optimising Largest Contentful Paint
csswizardry
37
3.6k
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
110
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
110
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
0
140
ラッコキーワード サービス紹介資料
rakko
1
2.2M
What's in a price? How to price your products and services
michaelherold
247
13k
Transcript
Zeroconf on iOS merpay Tech Talk #1
About me • Software Engineer at merpay • Twitter :
@_natpenguin • GitHub : natpenguin
Agenda • What is the Zeroconf? • Coding on iOS
Zeroconf
Zero Configuration Networking Zeroconf
Zeroconf connecting…
Zeroconf connected!
Zeroconf connected! No needed human operation
Zeroconf • To provide IP address • To automatically resolve
the host name • To automatically distribute the host name • To find services
History
AppleTalk
AppleTalk 1984
1984 # $
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
Problem
Load
Problem on AppleTalk
Problem on AppleTalk
TCP/IP
TCP/IP AppleTalk
AppleTalk
Bonjour
Bonjour • Instead of AppleTalk • Resolved the problem of
performance • Implementation on TCP/IP • AirPrint / AirPlay(AirTunes) • Only local network
Coding
Bonjour API • To provide IP address • To automatically
resolve the host name • To automatically distribute the host name • To find services
Bonjour API • To provide IP address • To automatically
resolve the host name • To automatically distribute the host name • To find services
Coding
Server NetService
Server let domain = "local." let type = "_awesome._tcp." let
name = "Awesome Service" let port: Int32 = 10000
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
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
https://www.iana.org/assignments/ service-names-port-numbers/ service-names-port-numbers.xhtml Document of Type
Client NetServiceBrowser
Client let domain = "local." let type = "_awesome._tcp."
Client let domain = "local." let type = "_awesome._tcp." browser.searchForServices(ofType:
type, inDomain: domain)
Client browser.searchForServices(ofType: type, inDomain: domain) func netServiceBrowser(_ browser: NetServiceBrowser, didFind
service: NetService, moreComing: Bool) let domain = "local." let type = "_awesome._tcp."
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
Client extension ViewController: NetServiceBrowserDelegate { func netServiceBrowser(_ browser: NetServiceBrowser, didFind
service: NetService, moreComing: Bool) { service.resolve(withTimeout: 10.0) } }
Client func netServiceDidResolveAddress(_ sender: NetService) extension ViewController: NetServiceBrowserDelegate { func
netServiceBrowser(_ browser: NetServiceBrowser, didFind service: NetService, moreComing: Bool) { service.resolve(withTimeout: 10.0) } }
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) } }
Client more BSD Socket CFSocket NSStream
https://developer.apple.com/ documentation/foundation/ netservice Document of NetService
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
Command $ dns-sd -B _printer._tcp Browsing a printer service
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
iOS12
Network.framework
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") }
Android https://github.com/mannodermaus/ RxBonjour https://github.com/andriydruk/ RxDNSSD https://github.com/HQarroum/ android-mdns
Paradigm Foo Foo
Paradigm Foo Foo Zeroconf
Paradigm
Paradigm Zeroconf
Let’s enjoy