本文整理汇总了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();
}
}