1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-01-17 06:52:18 +01:00

zeroconf: first raw impl

This commit is contained in:
Federico Fissore 2013-04-03 17:58:49 +02:00
parent bf3daeb86c
commit 32bb7f69de
3 changed files with 47 additions and 0 deletions

BIN
app/lib/jmdns-3.4.1.jar Normal file

Binary file not shown.

View File

@ -0,0 +1,11 @@
package processing.app.zeroconf;
import javax.jmdns.ServiceEvent;
public interface BoardListener {
void boardOffline(ServiceEvent serviceEvent);
void boardOnline(ServiceEvent serviceEvent);
}

View File

@ -0,0 +1,36 @@
package processing.app.zeroconf;
import javax.jmdns.JmDNS;
import javax.jmdns.NetworkTopologyDiscovery;
import javax.jmdns.ServiceEvent;
import javax.jmdns.ServiceListener;
import java.io.IOException;
import java.net.InetAddress;
public class Discovery implements ServiceListener {
private final BoardListener listener;
public Discovery(BoardListener listener) throws IOException {
this.listener = listener;
for (InetAddress addr : NetworkTopologyDiscovery.Factory.getInstance().getInetAddresses()) {
JmDNS jmDNS = JmDNS.create(addr);
jmDNS.addServiceListener("_arduino._tcp.local.", this);
}
}
@Override
public void serviceAdded(ServiceEvent serviceEvent) {
serviceEvent.getDNS().requestServiceInfo(serviceEvent.getInfo().getServer(), serviceEvent.getName(), true);
}
@Override
public void serviceRemoved(ServiceEvent serviceEvent) {
listener.boardOffline(serviceEvent);
}
@Override
public void serviceResolved(ServiceEvent serviceEvent) {
listener.boardOnline(serviceEvent);
}
}