当前位置: 首页>>代码示例>>Java>>正文


Java JmDNS.list方法代码示例

本文整理汇总了Java中javax.jmdns.JmDNS.list方法的典型用法代码示例。如果您正苦于以下问题:Java JmDNS.list方法的具体用法?Java JmDNS.list怎么用?Java JmDNS.list使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.jmdns.JmDNS的用法示例。


在下文中一共展示了JmDNS.list方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: search

import javax.jmdns.JmDNS; //导入方法依赖的package包/类
/**
 * Search for airplay devices within the given timeout, in ms.
 */
public List<AirPlay> search(int timeout) throws IOException {
    JmDNS jmdns = JmDNS.create(InetAddress.getByName("0.0.0.0"), null);
    ServiceInfo[] services = jmdns.list(DNSSD_TYPE, timeout);

    List<AirPlay> airplays = new ArrayList<AirPlay>();
    for(int i = 0; i < services.length; i++) {
        ServiceInfo service = services[i];
        Inet4Address[] addresses = service.getInet4Addresses();
        if(addresses.length >= 1) {
            airplays.add(new AirPlay(service.getName(),
                        addresses[0].getHostAddress(),
                        service.getPort()));
        }
    }
    jmdns.close();
    return airplays;
}
 
开发者ID:bvargo,项目名称:airplay,代码行数:21,代码来源:AirPlayFinder.java

示例2: testUnregisterService

import javax.jmdns.JmDNS; //导入方法依赖的package包/类
@Test
public void testUnregisterService() throws IOException, InterruptedException {
    System.out.println("Unit Test: testUnregisterService()");
    JmDNS registry = null;
    try {
        registry = JmDNS.create();
        registry.registerService(service);

        ServiceInfo[] services = registry.list(service.getType());
        assertEquals("We should see the service we just registered: ", 1, services.length);
        assertEquals(service, services[0]);

        // now unregister and make sure it's gone
        registry.unregisterService(services[0]);

        // 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);

        services = registry.list(service.getType());
        assertTrue("We should not see the service we just unregistered: ", services == null || services.length == 0);
    } finally {
        if (registry != null) registry.close();
    }
}
 
开发者ID:josephw,项目名称:jmdns,代码行数:26,代码来源:JmDNSTest.java

示例3: testListMyServiceIPV6

import javax.jmdns.JmDNS; //导入方法依赖的package包/类
@Test
public void testListMyServiceIPV6() throws IOException {
    System.out.println("Unit Test: testListMyServiceIPV6()");
    JmDNS registry = null;
    try {
        InetAddress address = InetAddress.getLocalHost();
        NetworkInterface interfaze = NetworkInterface.getByInetAddress(address);
        for (Enumeration<InetAddress> iaenum = interfaze.getInetAddresses(); iaenum.hasMoreElements();) {
            InetAddress interfaceAddress = iaenum.nextElement();
            if (interfaceAddress instanceof Inet6Address) {
                address = interfaceAddress;
            }
        }
        registry = JmDNS.create(address);
        registry.registerService(service);
        ServiceInfo[] services = registry.list(service.getType());
        assertEquals("We should see the service we just registered: ", 1, services.length);
        assertEquals(service, services[0]);
    } finally {
        if (registry != null) registry.close();
    }
}
 
开发者ID:josephw,项目名称:jmdns,代码行数:23,代码来源:JmDNSTest.java

示例4: __discoverIOTDevices

import javax.jmdns.JmDNS; //导入方法依赖的package包/类
private static List<IOTAddress> __discoverIOTDevices()
{
    log.debug("__discoverIOTDevices() entrance");
    try
    {
        final JmDNS mdnsService = JmDNS.create();
        log.debug("__discoverIOTDevices() JmDNS.create() finished");
        ServiceInfo[] serviceInfoArray = mdnsService.list(IOT_SERVICE_TYPE, timeout);
        List<IOTAddress> iotAddressList = __parseSeviceInfoArray2IOTAddressList(serviceInfoArray);
        // close the JmDNS asyn, for close() will take too much time, so we close it asyn
        EspBaseApiUtil.submit(new Runnable()
        {
            @Override
            public void run()
            {
                try
                {
                    mdnsService.close();
                }
                catch (IOException igrnoeException)
                {
                }
            }
        });
        return iotAddressList;
    }
    catch (IOException e)
    {
        e.printStackTrace();
    }
    log.debug("__discoverIOTDevices() exit with emptyList");
    return Collections.emptyList();
}
 
开发者ID:EspressifApp,项目名称:IOT-Espressif-Android,代码行数:34,代码来源:MdnsDiscoverUtil.java

示例5: testRenewExpiringRequests

import javax.jmdns.JmDNS; //导入方法依赖的package包/类
@Test
public void testRenewExpiringRequests() throws IOException, InterruptedException {
    System.out.println("Unit Test: testRenewExpiringRequests()");
    JmDNS registry = null;
    JmDNS newServiceRegistry = null;
    try {

        // To test for expiring TTL
        DNSStateTask.setDefaultTTL(1 * 60);

        registry = JmDNS.create("Listener");
        registry.addServiceListener(service.getType(), serviceListenerMock);
        //
        newServiceRegistry = JmDNS.create("Registry");
        newServiceRegistry.registerService(service);

        List<ServiceEvent> servicesAdded = serviceListenerMock.servicesAdded();
        assertTrue("We did not get the service added event.", servicesAdded.size() == 1);

        ServiceInfo[] services = registry.list(service.getType());
        assertEquals("We should see the service we just registered: ", 1, services.length);
        assertEquals(service, services[0]);

        // wait for the TTL
        Thread.sleep(2 * 60 * 1000);

        services = registry.list(service.getType());
        assertEquals("We should see the service after the renewal: ", 1, services.length);
        assertEquals(service, services[0]);

    } finally {
        if (registry != null) registry.close();
        if (newServiceRegistry != null) newServiceRegistry.close();
        DNSStateTask.setDefaultTTL(DNSConstants.DNS_TTL);
    }
}
 
开发者ID:josephw,项目名称:jmdns,代码行数:37,代码来源:TextUpdateTest.java

示例6: testRegisterService

import javax.jmdns.JmDNS; //导入方法依赖的package包/类
@Test
public void testRegisterService() throws IOException {
    System.out.println("Unit Test: testRegisterService()");
    JmDNS registry = null;
    try {
        registry = JmDNS.create();
        registry.registerService(service);

        ServiceInfo[] services = registry.list(service.getType());
        assertEquals("We should see the service we just registered: ", 1, services.length);
        assertEquals(service, services[0]);
    } finally {
        if (registry != null) registry.close();
    }
}
 
开发者ID:josephw,项目名称:jmdns,代码行数:16,代码来源:JmDNSTest.java

示例7: testUnregisterAndReregisterService

import javax.jmdns.JmDNS; //导入方法依赖的package包/类
@Test
public void testUnregisterAndReregisterService() throws IOException, InterruptedException {
    System.out.println("Unit Test: testUnregisterAndReregisterService()");
    JmDNS registry = null;
    try {
        registry = JmDNS.create();
        registry.registerService(service);

        ServiceInfo[] services = registry.list(service.getType());
        assertEquals("We should see the service we just registered: ", 1, services.length);
        assertEquals(service, services[0]);

        // now unregister and make sure it's gone
        registry.unregisterService(services[0]);

        // 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);

        services = registry.list(service.getType());
        assertTrue("We should not see the service we just unregistered: ", services == null || services.length == 0);

        registry.registerService(service);
        Thread.sleep(5000);
        services = registry.list(service.getType());
        assertTrue("We should see the service we just reregistered: ", services != null && services.length > 0);
    } finally {
        if (registry != null) registry.close();
    }
}
 
开发者ID:josephw,项目名称:jmdns,代码行数:31,代码来源:JmDNSTest.java

示例8: testListMyService

import javax.jmdns.JmDNS; //导入方法依赖的package包/类
@Test
public void testListMyService() throws IOException {
    System.out.println("Unit Test: testListMyService()");
    JmDNS registry = null;
    try {
        registry = JmDNS.create();
        registry.registerService(service);
        ServiceInfo[] services = registry.list(service.getType());
        assertEquals("We should see the service we just registered: ", 1, services.length);
        assertEquals(service, services[0]);
    } finally {
        if (registry != null) registry.close();
    }
}
 
开发者ID:josephw,项目名称:jmdns,代码行数:15,代码来源:JmDNSTest.java

示例9: testListenForMyServiceAndList

import javax.jmdns.JmDNS; //导入方法依赖的package包/类
@Test
public void testListenForMyServiceAndList() throws IOException {
    System.out.println("Unit Test: testListenForMyServiceAndList()");
    JmDNS registry = null;
    try {
        Capture<ServiceEvent> capServiceAddedEvent = new Capture<ServiceEvent>();
        Capture<ServiceEvent> capServiceResolvedEvent = new Capture<ServiceEvent>();
        // Expect the listener to be called once and capture the result
        serviceListenerMock.serviceAdded(capture(capServiceAddedEvent));
        serviceListenerMock.serviceResolved(capture(capServiceResolvedEvent));
        replay(serviceListenerMock);

        registry = JmDNS.create();
        registry.addServiceListener(service.getType(), serviceListenerMock);
        registry.registerService(service);

        // We get the service added event when we register the service. However the service has not been resolved at this point.
        // The info associated with the event only has the minimum information i.e. name and type.
        assertTrue("We did not get the service added event.", capServiceAddedEvent.hasCaptured());

        ServiceInfo info = capServiceAddedEvent.getValue().getInfo();
        assertEquals("We did not get the right name for the resolved service:", service.getName(), info.getName());
        assertEquals("We did not get the right type for the resolved service:", service.getType(), info.getType());

        // This will force the resolution of the service which in turn will get the listener called with a service resolved event.
        // The info associated with a service resolved event has all the information available.
        // Which in turn populates the ServiceInfo opbjects returned by JmDNS.list.
        ServiceInfo[] services = registry.list(info.getType());
        assertEquals("We did not get the expected number of services: ", 1, services.length);
        assertEquals("The service returned was not the one expected", service, services[0]);

        assertTrue("We did not get the service resolved event.", capServiceResolvedEvent.hasCaptured());
        verify(serviceListenerMock);
        ServiceInfo resolvedInfo = capServiceResolvedEvent.getValue().getInfo();
        assertEquals("Did not get the expected service info: ", service, resolvedInfo);
    } finally {
        if (registry != null) registry.close();
    }
}
 
开发者ID:josephw,项目名称:jmdns,代码行数:40,代码来源:JmDNSTest.java

示例10: 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();
    }
}
 
开发者ID:josephw,项目名称:jmdns,代码行数:32,代码来源:JmDNSTest.java

示例11: testListMyServiceWithToLowerCase

import javax.jmdns.JmDNS; //导入方法依赖的package包/类
@Test
public void testListMyServiceWithToLowerCase() throws IOException, InterruptedException {
    System.out.println("Unit Test: testListMyServiceWithToLowerCase()");
    String text = "Test hypothetical web server";
    Map<String, byte[]> properties = new HashMap<String, byte[]>();
    properties.put(serviceKey, text.getBytes());
    service = ServiceInfo.create("_HtmL._TcP.lOcAl.", "apache-someUniqueid", 80, 0, 0, true, properties);
    JmDNS registry = null;
    try {
        registry = JmDNS.create();
        registry.registerService(service);

        // with toLowerCase
        ServiceInfo[] services = registry.list(service.getType().toLowerCase());
        assertEquals("We should see the service we just registered: ", 1, services.length);
        assertEquals(service, services[0]);
        // now unregister and make sure it's gone
        registry.unregisterService(services[0]);
        // 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);
        services = registry.list(service.getType().toLowerCase());
        assertTrue("We should not see the service we just unregistered: ", services == null || services.length == 0);
    } finally {
        if (registry != null) registry.close();
    }
}
 
开发者ID:josephw,项目名称:jmdns,代码行数:28,代码来源:JmDNSTest.java

示例12: testListMyServiceWithoutLowerCase

import javax.jmdns.JmDNS; //导入方法依赖的package包/类
@Test
public void testListMyServiceWithoutLowerCase() throws IOException, InterruptedException {
    System.out.println("Unit Test: testListMyServiceWithoutLowerCase()");
    String text = "Test hypothetical web server";
    Map<String, byte[]> properties = new HashMap<String, byte[]>();
    properties.put(serviceKey, text.getBytes());
    service = ServiceInfo.create("_HtmL._TcP.lOcAl.", "apache-someUniqueid", 80, 0, 0, true, properties);
    JmDNS registry = null;
    try {
        registry = JmDNS.create();
        registry.registerService(service);

        // without toLowerCase
        ServiceInfo[] services = registry.list(service.getType());
        assertEquals("We should see the service we just registered: ", 1, services.length);
        assertEquals(service, services[0]);
        // now unregister and make sure it's gone
        registry.unregisterService(services[0]);
        // 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);
        services = registry.list(service.getType());
        assertTrue("We should not see the service we just unregistered: ", services == null || services.length == 0);
    } finally {
        if (registry != null) registry.close();
    }
}
 
开发者ID:josephw,项目名称:jmdns,代码行数:28,代码来源:JmDNSTest.java

示例13: testRegisterCaseSensitiveField

import javax.jmdns.JmDNS; //导入方法依赖的package包/类
@Test
public void testRegisterCaseSensitiveField() throws IOException {
    System.out.println("Unit Test: testRegisterCaseSensitiveField()");
    JmDNS registry = null;
    JmDNS newServiceRegistry = null;
    try {
        String text = "Test hypothetical Web Server";
        Map<String, byte[]> properties = new HashMap<String, byte[]>();
        properties.put(serviceKey, text.getBytes());
        service = ServiceInfo.create("_Html._Tcp.local.", "Apache-SomeUniqueId", 80, 0, 0, true, properties);

        registry = JmDNS.create("Listener");
        registry.addServiceListener(service.getType(), serviceListenerMock);
        //
        newServiceRegistry = JmDNS.create("Registry");
        newServiceRegistry.registerService(service);

        // We get the service added event when we register the service. However the service has not been resolved at this point.
        // The info associated with the event only has the minimum information i.e. name and type.
        List<ServiceEvent> servicesAdded = serviceListenerMock.servicesAdded();
        assertEquals("We did not get the service added event.", 1, servicesAdded.size());
        ServiceInfo info = servicesAdded.get(servicesAdded.size() - 1).getInfo();
        assertEquals("We did not get the right name for the resolved service:", service.getName(), info.getName());
        assertEquals("We did not get the right type for the resolved service:", service.getType(), info.getType());
        // We get the service added event when we register the service. However the service has not been resolved at this point.
        // The info associated with the event only has the minimum information i.e. name and type.
        List<ServiceEvent> servicesResolved = serviceListenerMock.servicesResolved();
        assertEquals("We did not get the service resolved event.", 1, servicesResolved.size());
        ServiceInfo result = servicesResolved.get(servicesResolved.size() - 1).getInfo();
        assertNotNull("Did not get the expected service info: ", result);
        assertEquals("Did not get the expected service info: ", service, result);
        assertEquals("Did not get the expected service info text: ", service.getPropertyString(serviceKey), result.getPropertyString(serviceKey));

        ServiceInfo[] infos = registry.list(service.getType());
        assertEquals("We did not get the right list of service info.", 1, infos.length);
        assertEquals("Did not get the expected service info: ", service, infos[0]);
        assertEquals("Did not get the expected service info text: ", service.getPropertyString(serviceKey), infos[0].getPropertyString(serviceKey));

        infos = registry.list(service.getType().toLowerCase());
        assertEquals("We did not get the right list of service info.", 1, infos.length);
        assertEquals("Did not get the expected service info: ", service, infos[0]);
        assertEquals("Did not get the expected service info text: ", service.getPropertyString(serviceKey), infos[0].getPropertyString(serviceKey));

    } finally {
        if (registry != null) registry.close();
        if (newServiceRegistry != null) newServiceRegistry.close();
    }
}
 
开发者ID:josephw,项目名称:jmdns,代码行数:49,代码来源:TextUpdateTest.java


注:本文中的javax.jmdns.JmDNS.list方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。