本文整理匯總了Java中javax.jmdns.JmDNS.getServiceInfo方法的典型用法代碼示例。如果您正苦於以下問題:Java JmDNS.getServiceInfo方法的具體用法?Java JmDNS.getServiceInfo怎麽用?Java JmDNS.getServiceInfo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.jmdns.JmDNS
的用法示例。
在下文中一共展示了JmDNS.getServiceInfo方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testWaitAndQueryForServiceOnOtherRegistry
import javax.jmdns.JmDNS; //導入方法依賴的package包/類
@Test
public void testWaitAndQueryForServiceOnOtherRegistry() throws IOException {
System.out.println("Unit Test: testWaitAndQueryForServiceOnOtherRegistry()");
JmDNS registry = null;
JmDNS newServiceRegistry = null;
try {
newServiceRegistry = JmDNS.create();
registry = JmDNS.create();
registry.registerService(service);
ServiceInfo fetchedService = newServiceRegistry.getServiceInfo(service.getType(), service.getName());
assertEquals("Did not get the expected service info: ", service, fetchedService);
} finally {
if (registry != null) registry.close();
if (newServiceRegistry != null) newServiceRegistry.close();
}
}
示例2: unregister
import javax.jmdns.JmDNS; //導入方法依賴的package包/類
public void unregister(String type, String domain, String name) {
for (JmDNS publisher : publishers) {
ServiceInfo serviceInfo = publisher.getServiceInfo(type + domain, name, 5000);
if (serviceInfo != null) {
publisher.unregisterService(serviceInfo);
}
}
}
示例3: ChromeCast
import javax.jmdns.JmDNS; //導入方法依賴的package包/類
ChromeCast(JmDNS mDNS, String name) {
this.name = name;
ServiceInfo serviceInfo = mDNS.getServiceInfo(SERVICE_TYPE, name);
this.address = serviceInfo.getInet4Addresses()[0].getHostAddress();
this.port = serviceInfo.getPort();
this.appsURL = serviceInfo.getURLs().length == 0 ? null : serviceInfo.getURLs()[0];
this.application = serviceInfo.getApplication();
this.title = serviceInfo.getPropertyString("fn");
this.appTitle = serviceInfo.getPropertyString("rs");
this.model = serviceInfo.getPropertyString("md");
}
示例4: testQueryMyService
import javax.jmdns.JmDNS; //導入方法依賴的package包/類
@Test
public void testQueryMyService() throws IOException {
System.out.println("Unit Test: testQueryMyService()");
JmDNS registry = null;
try {
registry = JmDNS.create();
registry.registerService(service);
ServiceInfo queriedService = registry.getServiceInfo(service.getType(), service.getName());
assertEquals(service, queriedService);
} finally {
if (registry != null) registry.close();
}
}
示例5: testRegisterAndListServiceOnOtherRegistry
import javax.jmdns.JmDNS; //導入方法依賴的package包/類
@Test
public void testRegisterAndListServiceOnOtherRegistry() throws IOException, InterruptedException {
System.out.println("Unit Test: testRegisterAndListServiceOnOtherRegistry()");
JmDNS registry = null;
JmDNS newServiceRegistry = null;
try {
registry = JmDNS.create("Registry");
registry.registerService(service);
newServiceRegistry = JmDNS.create("Listener");
Thread.sleep(6000);
ServiceInfo[] fetchedServices = newServiceRegistry.list(service.getType());
assertEquals("Did not get the expected services listed:", 1, fetchedServices.length);
assertEquals("Did not get the expected service type:", service.getType(), fetchedServices[0].getType());
assertEquals("Did not get the expected service name:", service.getName(), fetchedServices[0].getName());
assertEquals("Did not get the expected service fully qualified name:", service.getQualifiedName(), fetchedServices[0].getQualifiedName());
newServiceRegistry.getServiceInfo(service.getType(), service.getName());
assertEquals("Did not get the expected service info: ", service, fetchedServices[0]);
registry.close();
registry = null;
// According to the spec the record disappears from the cache 1s after it has been unregistered
// without sleeping for a while, the service would not be unregistered fully
Thread.sleep(1500);
fetchedServices = newServiceRegistry.list(service.getType());
assertEquals("The service was not cancelled after the close:", 0, fetchedServices.length);
} finally {
if (registry != null) registry.close();
if (newServiceRegistry != null) newServiceRegistry.close();
}
}