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.2k
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
170
The ownership in iOS
natpenguin
0
340
Featured
See All Featured
Keith and Marios Guide to Fast Websites
keithpitt
409
22k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
6.9k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Designing for humans not robots
tammielis
250
25k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
109
49k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.2k
Building Applications with DynamoDB
mza
90
6.1k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
4 Signs Your Business is Dying
shpigford
180
21k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
506
140k
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