SlideShare a Scribd company logo
1 of 35
Download to read offline
IT’S ZEROCONF
Bonjour Android
Roberto Orgiu
Giuseppe Mariniello
Android Developer
Backend Developer
WHAT IS ZEROCONF?
“ZERO-CONFIGURATION NETWORKING IS A SET OF
TECHNOLOGIES THAT AUTOMATICALLY CREATES A USABLE
COMPUTER NETWORK BASED ON THE INTERNET PROTOCOL
SUITE (TCP/IP) WHEN COMPUTERS OR NETWORK
PERIPHERALS ARE INTERCONNECTED.“
WHAT IS ZEROCONF
WHAT IS ZEROCONF
“IT DOES NOT REQUIRE MANUAL
OPERATOR INTERVENTION OR SPECIAL
CONFIGURATION SERVERS.“
WHERE CAN WE FIND
ZEROCONF?
ALMOST EVERYWHERE
BONJOUR ANDROID, IT’S ZEROCONF
THINK “DIFFERENT”
▸ ZeroConf is a standard
▸ UPnP/DLNA are somehow similar, but different people and ideas
▸ Apple has its own implementation, called Bonjour (once Rendezvous)
▸ On Android, we have very different solutions for using it
APPLE OFTEN REFERS TO ZEROCONF AS
BONJOUR, GIVING THEIR OWN
DEFINITION OF THE CONCEPTS
BONJOUR ANDROID, IT’S ZEROCONF
FUN FACT
Wut? Why do you even…?
BONJOUR ANDROID, IT’S ZEROCONF
HOW DOES IT WORK?
Ehy! I am 192.168.1.50
and I have the service
DroidConService running
on port 56472!
Great! Exactly what I was looking for!
BONJOUR ANDROID, IT’S ZEROCONF
▸ No infrastructure needed
▸ Simplicity over scalability
▸ 4 areas: IP interface configuration, translation between host name and IP
address, IP multicast address allocation, service discovery
▸ Aware of network changes
▸ Still a draft
HOW DOES IT WORK?
BONJOUR ANDROID, IT’S ZEROCONF
▸ Configure netmask
▸ Allocate unique IP address
IP INTERFACE CONFIGURATION
BONJOUR ANDROID, IT’S ZEROCONF
▸ Allows hostnames to be mapped to IP addresses and back
▸ Failure proof with retry mechanism
▸ Conflict detection
TRANSLATION BETWEEN HOST NAME AND IP ADDRESS
BONJOUR ANDROID, IT’S ZEROCONF
IP MULTICAST ADDRESS ALLOCATION
▸ List which of the scopes (local, site-local, link-local) are available
▸ Select a multicast address preventing conflicts
BONJOUR ANDROID, IT’S ZEROCONF
SERVICE DISCOVERY
▸ Service must be discoverable via identifier and/or type
▸ Discovery without the use of a service-specific protocol and should complete in
a timely manner (10s of seconds)
▸ Prompt detection of new services in a timely manner (10s of seconds)
D
R
A
F
T
BONJOUR ANDROID, IT’S ZEROCONF
HOW DOES IT WORK?
▸ Each part must start with _ (underscore)
▸ The second part only allows _tcp or _udp
_ServiceType._TransportProtocolName.
List of common services goo.gl/EXh1g
BONJOUR ANDROID, IT’S ZEROCONF
WHAT ABOUT ANDROID?
▸ API FROM 4.1
▸ JMDNS FOR JAVA
▸ APPLE NATIVE (C++) IMPLEMENTATION
BONJOUR ANDROID, IT’S ZEROCONF
JMDNS FOR JAVA
▸ Easy to implement
▸ Runs on the main thread, unless we specify otherwise
▸ Distributed as JAR or via Maven repo
▸ Long start-up time
▸ Compatible with all the Android versions
BONJOUR ANDROID, IT’S ZEROCONF
WHAT ABOUT ANDROID?
▸ API FROM 4.1
▸ JMDNS FOR JAVA
▸ APPLE NATIVE (C++) IMPLEMENTATION
BONJOUR ANDROID, IT’S ZEROCONF
APPLE NATIVE (C++) IMPLEMENTATION
▸ Ported to Android by Apple
▸ Open-sourced
▸ Needs Android NDK
▸ Few projects come with it already packed in
▸ Short startup time
▸ More complex logic
BONJOUR ANDROID, IT’S ZEROCONF
WHAT ABOUT ANDROID?
▸ API FROM 4.1
▸ JMDNS FOR JAVA
▸ APPLE NATIVE (C++) IMPLEMENTATION
BONJOUR ANDROID, IT’S ZEROCONF
ANDROID API
▸ From Android 4.1, custom attributes added with 5.1 (API 21)
▸ Already asynchronous, with return on the main thread
▸ Verbose, but easy to implement
▸ Based on two steps: discovery and resolution
▸ Only one service can be resolved at a time
http://developer.android.com/training/connect-devices-wirelessly/nsd.html
BONJOUR ANDROID, IT’S ZEROCONF
ANDROID API - SERVER
NsdServiceInfo serviceInfo = new NsdServiceInfo();
serviceInfo.setServiceName("DroidConService");
serviceInfo.setServiceType("_http._tcp.");
serviceInfo.setPort(randomPort);
nsdManager = Context.getSystemService(Context.NSD_SERVICE);
nsdManager.registerService(serviceInfo,
NsdManager.PROTOCOL_DNS_SD, mRegistrationListener);
Remember to unregister the service upon app closing!
BONJOUR ANDROID, IT’S ZEROCONF
ANDROID API - CLIENT
class Resolver extends NsdManager.ResolveListener {
@Override
public void onResolveFailed(NsdServiceInfo serviceInfo, int errorCode) {}
@Override
public void onServiceResolved(NsdServiceInfo serviceInfo) {
// here we can use our resolved service
}
};
Resolve resolveListener = new Resolve();
BONJOUR ANDROID, IT’S ZEROCONF
ANDROID API - CLIENT
class Resolver extends NsdManager.ResolveListener {
@Override
public void onResolveFailed(NsdServiceInfo serviceInfo, int errorCode) {}
@Override
public void onServiceResolved(NsdServiceInfo serviceInfo) {
// here we can use our resolved service
}
};
Resolve resolveListener = new Resolve();
BONJOUR ANDROID, IT’S ZEROCONF
ANDROID API - CLIENT
class SimpleDiscoveryListener extends NsdManager.DiscoveryListener {
@Override public void onDiscoveryStarted(String regType) {}
@Override public void onServiceFound(NsdServiceInfo service) {
if (service.getServiceName().contains(“DroidConService")){
nsdManager.resolveService(service, resolveListener);
}
}
@Override public void onServiceLost(NsdServiceInfo service) {}
@Override public void onDiscoveryStopped(String serviceType) {}
@Override public void onStartDiscoveryFailed(String serviceType, int errorCode) {
nsdManager.stopServiceDiscovery(this);
}
@Override public void onStopDiscoveryFailed(String serviceType, int errorCode) {
nsdManager.stopServiceDiscovery(this);
}};
BONJOUR ANDROID, IT’S ZEROCONF
ANDROID API - CLIENT
class SimpleDiscoveryListener extends NsdManager.DiscoveryListener {
@Override public void onDiscoveryStarted(String regType) {}
@Override public void onServiceFound(NsdServiceInfo service) {
if (service.getServiceName().contains(“DroidConService")){
nsdManager.resolveService(service, resolveListener);
}
}
@Override public void onServiceLost(NsdServiceInfo service) {}
@Override public void onDiscoveryStopped(String serviceType) {}
@Override public void onStartDiscoveryFailed(String serviceType, int errorCode) {
nsdManager.stopServiceDiscovery(this);
}
@Override public void onStopDiscoveryFailed(String serviceType, int errorCode) {
nsdManager.stopServiceDiscovery(this);
}};
BONJOUR ANDROID, IT’S ZEROCONF
ANDROID API - CLIENT
SimpleDiscoveryListener discoveryListener = new SimpleDiscoveryListener();
nsdManager.discoverServices(SERVICE_TYPE,
NsdManager.PROTOCOL_DNS_SD, discoveryListener);
nsdManager.stopServiceDiscovery(discoveryListener);
BONJOUR ANDROID, IT’S ZEROCONF
ANDROID API - CLIENT
SimpleDiscoveryListener discoveryListener = new SimpleDiscoveryListener();
nsdManager.discoverServices(SERVICE_TYPE,
NsdManager.PROTOCOL_DNS_SD, discoveryListener);
nsdManager.stopServiceDiscovery(discoveryListener);
ARE THERE BETTER
WAYS OF DOING IT?
YES, THERE ARE!
ARE THERE BETTER WAYS OF DOING IT
BONJOUR ANDROID, IT’S ZEROCONF
BETTER WAYS OF DOING IT
▸ better-zeroconf
▸ RxDNSSD
▸ RxBonjour
▸ ZeRxConf
▸ android-mdns
▸ JmDNS
▸ Apple mDNS
▸ Apple mDNS
▸ JmDNS + Android Native APIs
▸ Apple mDNS
DEMO TIME!
Q & A
CHECK THE REPO @ GITHUB.COM/ENNOVA-IT/DROIDCON-DEMO
BONJOUR ANDROID, IT’S ZEROCONF
THANKS FOR WATCHING!

More Related Content

What's hot

Cisco asa dhcp services
Cisco asa dhcp servicesCisco asa dhcp services
Cisco asa dhcp services
IT Tech
 
Network address translations
Network address translations Network address translations
Network address translations
Shahzad shareef
 
Chapter11ccna
Chapter11ccnaChapter11ccna
Chapter11ccna
robertoxe
 

What's hot (20)

Kamailio World 2018: Having fun with new stuff
Kamailio World 2018: Having fun with new stuffKamailio World 2018: Having fun with new stuff
Kamailio World 2018: Having fun with new stuff
 
Otto AI
Otto AIOtto AI
Otto AI
 
Packet Tracer: Nat protocol
Packet Tracer: Nat protocolPacket Tracer: Nat protocol
Packet Tracer: Nat protocol
 
Data communication part 7
Data communication part 7Data communication part 7
Data communication part 7
 
Ipo spaces calling document-v1
Ipo spaces calling document-v1Ipo spaces calling document-v1
Ipo spaces calling document-v1
 
X-Device Service Discovery
X-Device Service DiscoveryX-Device Service Discovery
X-Device Service Discovery
 
Nat
NatNat
Nat
 
NAT Scneario
NAT ScnearioNAT Scneario
NAT Scneario
 
Network Address Translation (NAT)
Network Address Translation (NAT)Network Address Translation (NAT)
Network Address Translation (NAT)
 
Astricon 2010: Scaling Asterisk installations
Astricon 2010: Scaling Asterisk installationsAstricon 2010: Scaling Asterisk installations
Astricon 2010: Scaling Asterisk installations
 
Cisco asa dhcp services
Cisco asa dhcp servicesCisco asa dhcp services
Cisco asa dhcp services
 
Nat pat
Nat patNat pat
Nat pat
 
WebRTC and Janus intro for FOSS Stockholm January 2019
WebRTC and Janus intro for FOSS Stockholm January 2019WebRTC and Janus intro for FOSS Stockholm January 2019
WebRTC and Janus intro for FOSS Stockholm January 2019
 
Build HA Asterisk on Microsoft Azure using DRBD/Heartbeat
Build HA Asterisk on Microsoft Azure using DRBD/HeartbeatBuild HA Asterisk on Microsoft Azure using DRBD/Heartbeat
Build HA Asterisk on Microsoft Azure using DRBD/Heartbeat
 
Network address translations
Network address translations Network address translations
Network address translations
 
Asterisk Deployments
Asterisk DeploymentsAsterisk Deployments
Asterisk Deployments
 
SWIFT: Tango's Infrastructure For Real-Time Video Call Service
SWIFT: Tango's Infrastructure For Real-Time Video Call ServiceSWIFT: Tango's Infrastructure For Real-Time Video Call Service
SWIFT: Tango's Infrastructure For Real-Time Video Call Service
 
Chapter11ccna
Chapter11ccnaChapter11ccna
Chapter11ccna
 
Static NAT
Static NATStatic NAT
Static NAT
 
NAT (network address translation) & PAT (port address translation)
NAT (network address translation) & PAT (port address translation)NAT (network address translation) & PAT (port address translation)
NAT (network address translation) & PAT (port address translation)
 

Similar to Bonjour Android, it's ZeroConf

Android Internals (This is not the droid you’re loking for...)
Android Internals (This is not the droid you’re loking for...)Android Internals (This is not the droid you’re loking for...)
Android Internals (This is not the droid you’re loking for...)
Giacomo Bergami
 
One Path to a Successful Implementation of NaturalONE
One Path to a Successful Implementation of NaturalONEOne Path to a Successful Implementation of NaturalONE
One Path to a Successful Implementation of NaturalONE
Software AG
 

Similar to Bonjour Android, it's ZeroConf (20)

Mobile development in 2020
Mobile development in 2020 Mobile development in 2020
Mobile development in 2020
 
Introduction to Cordova
Introduction to CordovaIntroduction to Cordova
Introduction to Cordova
 
Android
AndroidAndroid
Android
 
Connecting with the enterprise - The how and why of connecting to Enterprise ...
Connecting with the enterprise - The how and why of connecting to Enterprise ...Connecting with the enterprise - The how and why of connecting to Enterprise ...
Connecting with the enterprise - The how and why of connecting to Enterprise ...
 
React Native
React NativeReact Native
React Native
 
Ionic Hybrid Mobile Application
Ionic Hybrid Mobile ApplicationIonic Hybrid Mobile Application
Ionic Hybrid Mobile Application
 
Android Internals (This is not the droid you’re loking for...)
Android Internals (This is not the droid you’re loking for...)Android Internals (This is not the droid you’re loking for...)
Android Internals (This is not the droid you’re loking for...)
 
Cross platform mobile apps using .NET
Cross platform mobile apps using .NETCross platform mobile apps using .NET
Cross platform mobile apps using .NET
 
NanoSec Conference 2019: Code Execution Analysis in Mobile Apps - Abdullah Jo...
NanoSec Conference 2019: Code Execution Analysis in Mobile Apps - Abdullah Jo...NanoSec Conference 2019: Code Execution Analysis in Mobile Apps - Abdullah Jo...
NanoSec Conference 2019: Code Execution Analysis in Mobile Apps - Abdullah Jo...
 
Droidcon Turin 2015 - Android wear sdk introduction
Droidcon Turin 2015 - Android wear sdk introductionDroidcon Turin 2015 - Android wear sdk introduction
Droidcon Turin 2015 - Android wear sdk introduction
 
Android wear SDK introduction
Android wear SDK introductionAndroid wear SDK introduction
Android wear SDK introduction
 
Webinar on Google Android SDK
Webinar on Google Android SDKWebinar on Google Android SDK
Webinar on Google Android SDK
 
Izumi 1.0: Your Next Scala Stack
Izumi 1.0: Your Next Scala StackIzumi 1.0: Your Next Scala Stack
Izumi 1.0: Your Next Scala Stack
 
6-ZeroLab_decentralized_applications-2008.pptx
6-ZeroLab_decentralized_applications-2008.pptx6-ZeroLab_decentralized_applications-2008.pptx
6-ZeroLab_decentralized_applications-2008.pptx
 
React Native - Short introduction
React Native - Short introductionReact Native - Short introduction
React Native - Short introduction
 
Cucumber meets iPhone
Cucumber meets iPhoneCucumber meets iPhone
Cucumber meets iPhone
 
One Path to a Successful Implementation of NaturalONE
One Path to a Successful Implementation of NaturalONEOne Path to a Successful Implementation of NaturalONE
One Path to a Successful Implementation of NaturalONE
 
Ruby conf2012
Ruby conf2012Ruby conf2012
Ruby conf2012
 
FRIDA 101 Android
FRIDA 101 AndroidFRIDA 101 Android
FRIDA 101 Android
 
Binding android piece by piece
Binding android piece by pieceBinding android piece by piece
Binding android piece by piece
 

Recently uploaded

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Recently uploaded (20)

Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 

Bonjour Android, it's ZeroConf

  • 1. IT’S ZEROCONF Bonjour Android Roberto Orgiu Giuseppe Mariniello Android Developer Backend Developer
  • 3. “ZERO-CONFIGURATION NETWORKING IS A SET OF TECHNOLOGIES THAT AUTOMATICALLY CREATES A USABLE COMPUTER NETWORK BASED ON THE INTERNET PROTOCOL SUITE (TCP/IP) WHEN COMPUTERS OR NETWORK PERIPHERALS ARE INTERCONNECTED.“ WHAT IS ZEROCONF
  • 4. WHAT IS ZEROCONF “IT DOES NOT REQUIRE MANUAL OPERATOR INTERVENTION OR SPECIAL CONFIGURATION SERVERS.“
  • 5. WHERE CAN WE FIND ZEROCONF?
  • 7. BONJOUR ANDROID, IT’S ZEROCONF THINK “DIFFERENT” ▸ ZeroConf is a standard ▸ UPnP/DLNA are somehow similar, but different people and ideas ▸ Apple has its own implementation, called Bonjour (once Rendezvous) ▸ On Android, we have very different solutions for using it
  • 8. APPLE OFTEN REFERS TO ZEROCONF AS BONJOUR, GIVING THEIR OWN DEFINITION OF THE CONCEPTS BONJOUR ANDROID, IT’S ZEROCONF FUN FACT
  • 9. Wut? Why do you even…?
  • 10. BONJOUR ANDROID, IT’S ZEROCONF HOW DOES IT WORK? Ehy! I am 192.168.1.50 and I have the service DroidConService running on port 56472! Great! Exactly what I was looking for!
  • 11. BONJOUR ANDROID, IT’S ZEROCONF ▸ No infrastructure needed ▸ Simplicity over scalability ▸ 4 areas: IP interface configuration, translation between host name and IP address, IP multicast address allocation, service discovery ▸ Aware of network changes ▸ Still a draft HOW DOES IT WORK?
  • 12. BONJOUR ANDROID, IT’S ZEROCONF ▸ Configure netmask ▸ Allocate unique IP address IP INTERFACE CONFIGURATION
  • 13. BONJOUR ANDROID, IT’S ZEROCONF ▸ Allows hostnames to be mapped to IP addresses and back ▸ Failure proof with retry mechanism ▸ Conflict detection TRANSLATION BETWEEN HOST NAME AND IP ADDRESS
  • 14. BONJOUR ANDROID, IT’S ZEROCONF IP MULTICAST ADDRESS ALLOCATION ▸ List which of the scopes (local, site-local, link-local) are available ▸ Select a multicast address preventing conflicts
  • 15. BONJOUR ANDROID, IT’S ZEROCONF SERVICE DISCOVERY ▸ Service must be discoverable via identifier and/or type ▸ Discovery without the use of a service-specific protocol and should complete in a timely manner (10s of seconds) ▸ Prompt detection of new services in a timely manner (10s of seconds) D R A F T
  • 16. BONJOUR ANDROID, IT’S ZEROCONF HOW DOES IT WORK? ▸ Each part must start with _ (underscore) ▸ The second part only allows _tcp or _udp _ServiceType._TransportProtocolName. List of common services goo.gl/EXh1g
  • 17. BONJOUR ANDROID, IT’S ZEROCONF WHAT ABOUT ANDROID? ▸ API FROM 4.1 ▸ JMDNS FOR JAVA ▸ APPLE NATIVE (C++) IMPLEMENTATION
  • 18. BONJOUR ANDROID, IT’S ZEROCONF JMDNS FOR JAVA ▸ Easy to implement ▸ Runs on the main thread, unless we specify otherwise ▸ Distributed as JAR or via Maven repo ▸ Long start-up time ▸ Compatible with all the Android versions
  • 19. BONJOUR ANDROID, IT’S ZEROCONF WHAT ABOUT ANDROID? ▸ API FROM 4.1 ▸ JMDNS FOR JAVA ▸ APPLE NATIVE (C++) IMPLEMENTATION
  • 20. BONJOUR ANDROID, IT’S ZEROCONF APPLE NATIVE (C++) IMPLEMENTATION ▸ Ported to Android by Apple ▸ Open-sourced ▸ Needs Android NDK ▸ Few projects come with it already packed in ▸ Short startup time ▸ More complex logic
  • 21. BONJOUR ANDROID, IT’S ZEROCONF WHAT ABOUT ANDROID? ▸ API FROM 4.1 ▸ JMDNS FOR JAVA ▸ APPLE NATIVE (C++) IMPLEMENTATION
  • 22. BONJOUR ANDROID, IT’S ZEROCONF ANDROID API ▸ From Android 4.1, custom attributes added with 5.1 (API 21) ▸ Already asynchronous, with return on the main thread ▸ Verbose, but easy to implement ▸ Based on two steps: discovery and resolution ▸ Only one service can be resolved at a time http://developer.android.com/training/connect-devices-wirelessly/nsd.html
  • 23. BONJOUR ANDROID, IT’S ZEROCONF ANDROID API - SERVER NsdServiceInfo serviceInfo = new NsdServiceInfo(); serviceInfo.setServiceName("DroidConService"); serviceInfo.setServiceType("_http._tcp."); serviceInfo.setPort(randomPort); nsdManager = Context.getSystemService(Context.NSD_SERVICE); nsdManager.registerService(serviceInfo, NsdManager.PROTOCOL_DNS_SD, mRegistrationListener); Remember to unregister the service upon app closing!
  • 24. BONJOUR ANDROID, IT’S ZEROCONF ANDROID API - CLIENT class Resolver extends NsdManager.ResolveListener { @Override public void onResolveFailed(NsdServiceInfo serviceInfo, int errorCode) {} @Override public void onServiceResolved(NsdServiceInfo serviceInfo) { // here we can use our resolved service } }; Resolve resolveListener = new Resolve();
  • 25. BONJOUR ANDROID, IT’S ZEROCONF ANDROID API - CLIENT class Resolver extends NsdManager.ResolveListener { @Override public void onResolveFailed(NsdServiceInfo serviceInfo, int errorCode) {} @Override public void onServiceResolved(NsdServiceInfo serviceInfo) { // here we can use our resolved service } }; Resolve resolveListener = new Resolve();
  • 26. BONJOUR ANDROID, IT’S ZEROCONF ANDROID API - CLIENT class SimpleDiscoveryListener extends NsdManager.DiscoveryListener { @Override public void onDiscoveryStarted(String regType) {} @Override public void onServiceFound(NsdServiceInfo service) { if (service.getServiceName().contains(“DroidConService")){ nsdManager.resolveService(service, resolveListener); } } @Override public void onServiceLost(NsdServiceInfo service) {} @Override public void onDiscoveryStopped(String serviceType) {} @Override public void onStartDiscoveryFailed(String serviceType, int errorCode) { nsdManager.stopServiceDiscovery(this); } @Override public void onStopDiscoveryFailed(String serviceType, int errorCode) { nsdManager.stopServiceDiscovery(this); }};
  • 27. BONJOUR ANDROID, IT’S ZEROCONF ANDROID API - CLIENT class SimpleDiscoveryListener extends NsdManager.DiscoveryListener { @Override public void onDiscoveryStarted(String regType) {} @Override public void onServiceFound(NsdServiceInfo service) { if (service.getServiceName().contains(“DroidConService")){ nsdManager.resolveService(service, resolveListener); } } @Override public void onServiceLost(NsdServiceInfo service) {} @Override public void onDiscoveryStopped(String serviceType) {} @Override public void onStartDiscoveryFailed(String serviceType, int errorCode) { nsdManager.stopServiceDiscovery(this); } @Override public void onStopDiscoveryFailed(String serviceType, int errorCode) { nsdManager.stopServiceDiscovery(this); }};
  • 28. BONJOUR ANDROID, IT’S ZEROCONF ANDROID API - CLIENT SimpleDiscoveryListener discoveryListener = new SimpleDiscoveryListener(); nsdManager.discoverServices(SERVICE_TYPE, NsdManager.PROTOCOL_DNS_SD, discoveryListener); nsdManager.stopServiceDiscovery(discoveryListener);
  • 29. BONJOUR ANDROID, IT’S ZEROCONF ANDROID API - CLIENT SimpleDiscoveryListener discoveryListener = new SimpleDiscoveryListener(); nsdManager.discoverServices(SERVICE_TYPE, NsdManager.PROTOCOL_DNS_SD, discoveryListener); nsdManager.stopServiceDiscovery(discoveryListener);
  • 30. ARE THERE BETTER WAYS OF DOING IT?
  • 31. YES, THERE ARE! ARE THERE BETTER WAYS OF DOING IT
  • 32. BONJOUR ANDROID, IT’S ZEROCONF BETTER WAYS OF DOING IT ▸ better-zeroconf ▸ RxDNSSD ▸ RxBonjour ▸ ZeRxConf ▸ android-mdns ▸ JmDNS ▸ Apple mDNS ▸ Apple mDNS ▸ JmDNS + Android Native APIs ▸ Apple mDNS
  • 34. Q & A CHECK THE REPO @ GITHUB.COM/ENNOVA-IT/DROIDCON-DEMO
  • 35. BONJOUR ANDROID, IT’S ZEROCONF THANKS FOR WATCHING!