use of javax.jmdns.ServiceInfo in project UniversalMediaServer by UniversalMediaServer.
the class ChromecastMgr method serviceAdded.
@Override
public void serviceAdded(ServiceEvent event) {
if (event.getInfo() == null) {
LOGGER.debug("Bad Chromcast event: {}", event.toString());
return;
}
LOGGER.debug("Found chromecast: {}", event.getInfo().getName());
ServiceInfo serviceInfo = mDNS.getServiceInfo(ChromeCast.SERVICE_TYPE, event.getInfo().getName());
ChromeCast chromeCast = new ChromeCast(serviceInfo.getInet4Addresses()[0].getHostAddress(), serviceInfo.getPort());
chromeCast.setName(event.getInfo().getName());
chromeCast.setAppsURL(serviceInfo.getURLs().length == 0 ? null : serviceInfo.getURLs()[0]);
chromeCast.setApplication(serviceInfo.getApplication());
try {
chromeCast.connect();
chromeCasts.add(new ChromeDevice(chromeCast, renderer, InetAddress.getByName(chromeCast.getAddress())));
} catch (IOException | GeneralSecurityException | ConfigurationException e) {
LOGGER.error("Chromecast registration failed with the following error: {}", e);
LOGGER.trace("", e);
}
}
use of javax.jmdns.ServiceInfo in project arduino-eclipse-plugin by Sloeber.
the class NetworkDiscovery method serviceResolved.
@SuppressWarnings("nls")
@Override
public void serviceResolved(ServiceEvent serviceEvent) {
ServiceInfo info = serviceEvent.getInfo();
for (InetAddress inetAddress : info.getInet4Addresses()) {
String address = inetAddress.getHostAddress();
String name = serviceEvent.getName();
BoardPort port = new BoardPort();
String board = null;
String description = null;
if (info.hasData()) {
board = info.getPropertyString("board");
description = info.getPropertyString("description");
port.getPrefs().put("board", board);
port.getPrefs().put("distro_version", info.getPropertyString("distro_version"));
port.getPrefs().put("port", "" + info.getPort());
// Add additional fields to permit generic ota updates
// and make sure we do not intefere with Arduino boards
// define "ssh_upload=no" TXT property to use generic uploader
// define "tcp_check=no" TXT property if you are not using TCP
// define "auth_upload=yes" TXT property if you want to use authenticated generic upload
String useSSH = info.getPropertyString("ssh_upload");
String checkTCP = info.getPropertyString("tcp_check");
String useAuth = info.getPropertyString("auth_upload");
if (useSSH == null || !useSSH.contentEquals("no"))
useSSH = "yes";
if (checkTCP == null || !checkTCP.contentEquals("no"))
checkTCP = "yes";
if (useAuth == null || !useAuth.contentEquals("yes"))
useAuth = "no";
port.getPrefs().put("ssh_upload", useSSH);
port.getPrefs().put("tcp_check", checkTCP);
port.getPrefs().put("auth_upload", useAuth);
}
String label = name + " at " + address;
// if (board != null && BaseNoGui.packages != null) {
// String boardName = BaseNoGui.getPlatform().resolveDeviceByBoardID(BaseNoGui.packages, board);
// if (boardName != null) {
// label += " (" + boardName + ")";
// }
// } else if (description != null) {
label += " (" + description + ")";
// }
port.setAddress(address);
port.setBoardName(name);
port.setProtocol("network");
port.setLabel(label);
synchronized (this.boardPortsDiscoveredWithJmDNS) {
removeDuplicateBoards(port);
this.boardPortsDiscoveredWithJmDNS.add(port);
}
}
}
use of javax.jmdns.ServiceInfo in project webthing-java by mozilla-iot.
the class WebThingServer method start.
/**
* Start listening for incoming connections.
*
* @param daemon Whether or not to daemonize the server
* @throws IOException on failure to listen on port
*/
public void start(boolean daemon) throws IOException {
this.jmdns = JmDNS.create(InetAddress.getLocalHost());
String url = String.format("url=%s://%s:%d/", this.isTls ? "https" : "http", this.ip, this.port);
ServiceInfo serviceInfo = ServiceInfo.create("_http._tcp.local", this.name, "_webthing", this.port, url);
this.jmdns.registerService(serviceInfo);
super.start(NanoHTTPD.SOCKET_READ_TIMEOUT, daemon);
}
use of javax.jmdns.ServiceInfo in project smarthome by eclipse.
the class MDNSClientImpl method unregisterService.
@Override
public void unregisterService(ServiceDescription description) {
for (JmDNS instance : jmdnsInstances) {
try {
logger.debug("Unregistering service {} at {}:{} ({})", description.serviceType, instance.getInetAddress().getHostAddress(), description.servicePort, instance.getName());
} catch (IOException e) {
logger.debug("Unregistering service {} ({})", description.serviceType, instance.getName());
}
ServiceInfo serviceInfo = ServiceInfo.create(description.serviceType, description.serviceName, description.servicePort, 0, 0, description.serviceProperties);
instance.unregisterService(serviceInfo);
}
}
use of javax.jmdns.ServiceInfo in project JAirPort by froks.
the class JmDNSImpl method updateRecord.
// Remind: Method updateRecord should receive a better name.
/**
* Notify all listeners that a record was updated.
*
* @param now
* update date
* @param rec
* DNS record
* @param operation
* DNS cache operation
*/
public void updateRecord(long now, DNSRecord rec, Operation operation) {
// We do not want to block the entire DNS while we are updating the record for each listener (service info)
{
List<DNSListener> listenerList = null;
synchronized (_listeners) {
listenerList = new ArrayList<DNSListener>(_listeners);
}
for (DNSListener listener : listenerList) {
listener.updateRecord(this.getCache(), now, rec);
}
}
if (DNSRecordType.TYPE_PTR.equals(rec.getRecordType())) // if (DNSRecordType.TYPE_PTR.equals(rec.getRecordType()) || DNSRecordType.TYPE_SRV.equals(rec.getRecordType()))
{
ServiceEvent event = rec.getServiceEvent(this);
if ((event.getInfo() == null) || !event.getInfo().hasData()) {
// We do not care about the subtype because the info is only used if complete and the subtype will then be included.
ServiceInfo info = this.getServiceInfoFromCache(event.getType(), event.getName(), "", false);
if (info.hasData()) {
event = new ServiceEventImpl(this, event.getType(), event.getName(), info);
}
}
List<ServiceListenerStatus> list = _serviceListeners.get(event.getType().toLowerCase());
final List<ServiceListenerStatus> serviceListenerList;
if (list != null) {
synchronized (list) {
serviceListenerList = new ArrayList<ServiceListenerStatus>(list);
}
} else {
serviceListenerList = Collections.emptyList();
}
if (logger.isLoggable(Level.FINEST)) {
logger.finest(this.getName() + ".updating record for event: " + event + " list " + serviceListenerList + " operation: " + operation);
}
if (!serviceListenerList.isEmpty()) {
final ServiceEvent localEvent = event;
switch(operation) {
case Add:
for (final ServiceListenerStatus listener : serviceListenerList) {
if (listener.isSynchronous()) {
listener.serviceAdded(localEvent);
} else {
_executor.submit(new Runnable() {
/**
* {@inheritDoc}
*/
@Override
public void run() {
listener.serviceAdded(localEvent);
}
});
}
}
break;
case Remove:
for (final ServiceListenerStatus listener : serviceListenerList) {
if (listener.isSynchronous()) {
listener.serviceRemoved(localEvent);
} else {
_executor.submit(new Runnable() {
/**
* {@inheritDoc}
*/
@Override
public void run() {
listener.serviceRemoved(localEvent);
}
});
}
}
break;
default:
break;
}
}
}
}
Aggregations