Upload
hendrik-ebbers
View
3.255
Download
2
Embed Size (px)
DESCRIPTION
How to use Bonjour in Java The slides show you how to create bonjour based services on server site and use them on client site. All examples are completely written in Java.
Citation preview
Content• ZeroConf & Bonjour
• AirPlay
• Java API
• Demoskeep your fingers crossed for me
HomeAutomationModule
Welcome,please configure your Home Automation Server:
IP-Adress
Port
ok
Example
Spooky,
isn‘t it?
ANTIPATTERN!!
HomeAutomationModule
Hi,please choose your Home Automation Server:
ok
HA Server living room (12.0.0.34:9001)My Server pool house (12.0.0.31:9001)
This is how it goes
Cool, isn‘t it?
ZeroConf• methodology and set of special technologies
• automatically create a usable computer network
• assign numeric network addresses to devices
• distribution and resolution of hostnames
• location of network services
Bonjour
• Based on ZeroConf
• provides a general method to discover services on a local area network
• Used in many tools & applications
• Open SourcepostgreSQL, Adobe Creative Suite, Skype...
Airplay• Default Services based on Bonjour
• Stream Music, Movies & Photos from iOS to Apple TV
• No configuration needed
Find this icon on your iDevice
User has time for other stuff
Defining a Service
• Each service has a type that is defined by a namespace
• „_servicetype._tcp.local.“
• Each service has a name
• Each service has a host and a port
• Services can have descriptions and other properties
• iOS Devices can stream Photos to Apple TV
• Communication is based on Bonjour & REST
• Find AirPlay Server with Bonjour
• Send pictures with REST call
Stream Photos
REST call
Stream Music
• iOS Devices can stream Music to Apple TV
• Same Workflow as with pictures
• _airplay._tcp.local.
• Communication is completely based on REST
default service type for Airplay
... and documented in the web
JmDNS• Java implementation of multi-cast DNS
• fully compatible with Apple's Bonjour
• provide simple ways for services to register themselves
• discover multicast DNS based services
http://jmdns.sourceforge.net
Listen to a Service
JmDNS jmDNS = JmDNS.create();
jmDNS.addServiceListener("name._tcp.local.", new ServiceListener() {
@Override! ! ! public void serviceAdded(ServiceEvent event) {...}
! ! ! @Override! ! ! public void serviceResolved(ServiceEvent event) {...}
! ! ! @Override! ! ! public void serviceRemoved(ServiceEvent event) {...} });
create Context
listener concept
lifec
ylce
wraps all infos
Listen to a Service
@Overridepublic void serviceResolved(ServiceEvent event) {! System.out.println("Type:" + event.getType());! System.out.println("Name:" + event.getName());! ! ! !! System.out.println("IP:" + event.getInfo().getHostAddress());! System.out.println("Port:" + event.getInfo().getPort());! System.out.println("Name:" + event.getInfo().getName());
! System.out.println("Desc:" + event.getInfo().getNiceTextString());! System.out.println("Entry Point:" + event.getInfo().getURL());}
optional properties
Create a Service
JmDNS jmDNS = JmDNS.create();
ServiceInfo info = ServiceInfo.create("_demo1._tcp.local.", "Demo 1", 9090, "I‘m a demo");
jmDNS.registerService(info);
create Context
register on network
type, name, port, description
Example//ServerRestServer server = new RestServer();server.startMp3Player(„/play“, 9090);
JmDNS jmDNS = JmDNS.create();ServiceInfo info = ServiceInfo.create("playmp3._tcp.local.", "MP3 Player", 9090, "play a mp3 file");jmDNS.registerService(info);
//ClientjmDNS.addServiceListener("playmp3._tcp.local.", new ServiceListener() { @Override! ! ! public void serviceAdded(ServiceEvent event) { RestClient.play(„tuut.mp3“, event, „/play“); }});
create REST Server
create DNS Service
REST Call
REST
• Implement your services as REST WS
• Client only needs to know the URL path
• I used Vert.x
You can use any REST API
Cause it`s cool
Port
Example
Demo Time