unable to get txtrecords from ServiceEvent in the function serviceAdded (From JmDNS)

StackOverflow https://stackoverflow.com/questions/12401822

  •  01-07-2021
  •  | 
  •  

I 'm unable to get txtrecord from ServiceEvent in the function serviceAdded (From JmDNS).

but I m able to get txtrecord from ServiceEvent in the function serviceResolved

The serviceResolved is executed at the start-up only 1 time and does not capte all services.

The serviceAdded is execute each time it capte a new service. but when trying to access to txtrecord, I found nothing in txtrecord I found only the service name.

are there a solution to get all txtRecord each time I capte a new service ?

有帮助吗?

解决方案

The service info associated with the event of serviceAdded method does not include resolution information. To get the full resolved information we need to call JmDNS.getServiceInfo(String, String, long)

public void serviceAdded(ServiceEvent event) {
                   ServiceInfo inf = event.getDNS().getServiceInfo(event.getType(), event.getName());
               }

Reference: http://jmdns.sourceforge.net/apidocs/javax/jmdns/ServiceListener.html

其他提示

Also can be done by

 public void serviceAdded(ServiceEvent event) {
                event.getDNS().requestServiceInfo(event.getType(), event.getName(), true);
 }

This will request for service resolution.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top