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:
parent
bf3daeb86c
commit
32bb7f69de
BIN
app/lib/jmdns-3.4.1.jar
Normal file
BIN
app/lib/jmdns-3.4.1.jar
Normal file
Binary file not shown.
11
app/src/processing/app/zeroconf/BoardListener.java
Normal file
11
app/src/processing/app/zeroconf/BoardListener.java
Normal file
@ -0,0 +1,11 @@
|
||||
package processing.app.zeroconf;
|
||||
|
||||
import javax.jmdns.ServiceEvent;
|
||||
|
||||
public interface BoardListener {
|
||||
|
||||
void boardOffline(ServiceEvent serviceEvent);
|
||||
|
||||
void boardOnline(ServiceEvent serviceEvent);
|
||||
|
||||
}
|
36
app/src/processing/app/zeroconf/Discovery.java
Normal file
36
app/src/processing/app/zeroconf/Discovery.java
Normal 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);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user