Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.
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 ...
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 p...
APPLE OFTEN REFERS TO ZEROCONF AS
BONJOUR, GIVING THEIR OWN
DEFINITION OF THE CONCEPTS
BONJOUR ANDROID, IT’S ZEROCONF
FUN ...
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 ...
BONJOUR ANDROID, IT’S ZEROCONF
▸ No infrastructure needed
▸ Simplicity over scalability
▸ 4 areas: IP interface configurati...
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 mechani...
BONJOUR ANDROID, IT’S ZEROCONF
IP MULTICAST ADDRESS ALLOCATION
▸ List which of the scopes (local, site-local, link-local) ...
BONJOUR ANDROID, IT’S ZEROCONF
SERVICE DISCOVERY
▸ Service must be discoverable via identifier and/or type
▸ Discovery with...
BONJOUR ANDROID, IT’S ZEROCONF
HOW DOES IT WORK?
▸ Each part must start with _ (underscore)
▸ The second part only allows ...
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
▸...
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 Andro...
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 asynchr...
BONJOUR ANDROID, IT’S ZEROCONF
ANDROID API - SERVER
NsdServiceInfo serviceInfo = new NsdServiceInfo();
serviceInfo.setServ...
BONJOUR ANDROID, IT’S ZEROCONF
ANDROID API - CLIENT
class Resolver extends NsdManager.ResolveListener {
@Override
public v...
BONJOUR ANDROID, IT’S ZEROCONF
ANDROID API - CLIENT
class Resolver extends NsdManager.ResolveListener {
@Override
public v...
BONJOUR ANDROID, IT’S ZEROCONF
ANDROID API - CLIENT
class SimpleDiscoveryListener extends NsdManager.DiscoveryListener {
@...
BONJOUR ANDROID, IT’S ZEROCONF
ANDROID API - CLIENT
class SimpleDiscoveryListener extends NsdManager.DiscoveryListener {
@...
BONJOUR ANDROID, IT’S ZEROCONF
ANDROID API - CLIENT
SimpleDiscoveryListener discoveryListener = new SimpleDiscoveryListene...
BONJOUR ANDROID, IT’S ZEROCONF
ANDROID API - CLIENT
SimpleDiscoveryListener discoveryListener = new SimpleDiscoveryListene...
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
▸...
DEMO TIME!
Q & A
CHECK THE REPO @ GITHUB.COM/ENNOVA-IT/DROIDCON-DEMO
BONJOUR ANDROID, IT’S ZEROCONF
THANKS FOR WATCHING!
Nächste SlideShare
Wird geladen in …5
×

Bonjour Android, it's ZeroConf

1.692 Aufrufe

Veröffentlicht am

ZeroConf is a protocol that helps us advertising a service or discovering the available services in our networks. This is how Chromecast works, but why don’t we go deeper?

- What is ZeroConf
– Why is it needed
– Discovery VS Advertising
– What are the different implementations that we can find on Android
– And on server side?
– Small demo and code show

Veröffentlicht in: Technologie
  • Als Erste(r) kommentieren

Bonjour Android, it's ZeroConf

  1. 1. IT’S ZEROCONF Bonjour Android Roberto Orgiu Giuseppe Mariniello Android Developer Backend Developer
  2. 2. WHAT IS ZEROCONF?
  3. 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. 4. WHAT IS ZEROCONF “IT DOES NOT REQUIRE MANUAL OPERATOR INTERVENTION OR SPECIAL CONFIGURATION SERVERS.“
  5. 5. WHERE CAN WE FIND ZEROCONF?
  6. 6. ALMOST EVERYWHERE
  7. 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. 8. APPLE OFTEN REFERS TO ZEROCONF AS BONJOUR, GIVING THEIR OWN DEFINITION OF THE CONCEPTS BONJOUR ANDROID, IT’S ZEROCONF FUN FACT
  9. 9. Wut? Why do you even…?
  10. 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. 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. 12. BONJOUR ANDROID, IT’S ZEROCONF ▸ Configure netmask ▸ Allocate unique IP address IP INTERFACE CONFIGURATION
  13. 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. 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. 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. 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. 17. BONJOUR ANDROID, IT’S ZEROCONF WHAT ABOUT ANDROID? ▸ API FROM 4.1 ▸ JMDNS FOR JAVA ▸ APPLE NATIVE (C++) IMPLEMENTATION
  18. 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. 19. BONJOUR ANDROID, IT’S ZEROCONF WHAT ABOUT ANDROID? ▸ API FROM 4.1 ▸ JMDNS FOR JAVA ▸ APPLE NATIVE (C++) IMPLEMENTATION
  20. 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. 21. BONJOUR ANDROID, IT’S ZEROCONF WHAT ABOUT ANDROID? ▸ API FROM 4.1 ▸ JMDNS FOR JAVA ▸ APPLE NATIVE (C++) IMPLEMENTATION
  22. 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. 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. 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. 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. 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. 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. 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. 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. 30. ARE THERE BETTER WAYS OF DOING IT?
  31. 31. YES, THERE ARE! ARE THERE BETTER WAYS OF DOING IT
  32. 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
  33. 33. DEMO TIME!
  34. 34. Q & A CHECK THE REPO @ GITHUB.COM/ENNOVA-IT/DROIDCON-DEMO
  35. 35. BONJOUR ANDROID, IT’S ZEROCONF THANKS FOR WATCHING!

×