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


Java JmmDNS类代码示例

本文整理汇总了Java中javax.jmdns.JmmDNS的典型用法代码示例。如果您正苦于以下问题:Java JmmDNS类的具体用法?Java JmmDNS怎么用?Java JmmDNS使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: Zeroconf

import javax.jmdns.JmmDNS; //导入依赖的package包/类
public Zeroconf() {
    /********************
     * Variables
     *******************/
    this.jmmdns = JmmDNS.Factory.getInstance();
    this.listeners = new HashSet<String>();
    this.services = new HashSet<ServiceInfo>();
    this.logger = new DefaultLogger();
    this.listener_callbacks = new HashMap<String, ZeroconfDiscoveryHandler>();
    this.default_listener_callback = null;

    /********************
     * Methods
     *******************/
    // be nice to get rid of this completely - and have it in the jmdns library itself.
    this.jmmdns.addNetworkTopologyListener(this);
}
 
开发者ID:rosalfred,项目名称:smarthome_network_zeroconf,代码行数:18,代码来源:Zeroconf.java

示例2: startMdns

import javax.jmdns.JmmDNS; //导入依赖的package包/类
private void startMdns() {
	//DNS-SD
	//NetworkTopologyDiscovery netTop = NetworkTopologyDiscovery.Factory.getInstance();
	Runnable r = new Runnable() {
		
		@Override
		public void run() {
			jmdns = JmmDNS.Factory.getInstance();
			
			jmdns.registerServiceType(SignalKConstants._SIGNALK_WS_TCP_LOCAL);
			jmdns.registerServiceType(SignalKConstants._SIGNALK_HTTP_TCP_LOCAL);
			ServiceInfo wsInfo = ServiceInfo.create(SignalKConstants._SIGNALK_WS_TCP_LOCAL,"signalk-ws",Util.getConfigPropertyInt(ConfigConstants.WEBSOCKET_PORT), 0,0, getMdnsTxt());
			try {
				jmdns.registerService(wsInfo);
				ServiceInfo httpInfo = ServiceInfo
					.create(SignalKConstants._SIGNALK_HTTP_TCP_LOCAL, "signalk-http",Util.getConfigPropertyInt(ConfigConstants.REST_PORT),0,0, getMdnsTxt());
				jmdns.registerService(httpInfo);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	};
	Thread t = new Thread(r);
	t.setDaemon(true);
	t.start();
	
}
 
开发者ID:SignalK,项目名称:signalk-server-java,代码行数:28,代码来源:SignalKServer.java

示例3: testCreateINet

import javax.jmdns.JmmDNS; //导入依赖的package包/类
@Test
public void testCreateINet() throws IOException {
    System.out.println("Unit Test: testCreateINet()");
    JmmDNS registry = JmmDNS.Factory.getInstance();
    // assertEquals("We did not register on the local host inet:", InetAddress.getLocalHost(), registry.getInterface());
    registry.close();
}
 
开发者ID:josephw,项目名称:jmdns,代码行数:8,代码来源:JmmDNSTest.java

示例4: testRegisterService

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

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

示例5: testQueryMyService

import javax.jmdns.JmmDNS; //导入依赖的package包/类
@Test
public void testQueryMyService() throws IOException {
    System.out.println("Unit Test: testQueryMyService()");
    JmmDNS registry = null;
    try {
        registry = JmmDNS.Factory.getInstance();
        registry.registerService(service);

        ServiceInfo[] queriedService = registry.getServiceInfos(service.getType(), service.getName());
        assertTrue("We expect to see the service we just registered", queriedService.length > 0);
        assertEquals(service, queriedService[0]);
    } finally {
        if (registry != null) registry.close();
    }
}
 
开发者ID:josephw,项目名称:jmdns,代码行数:16,代码来源:JmmDNSTest.java

示例6: testListMyService

import javax.jmdns.JmmDNS; //导入依赖的package包/类
@Test
public void testListMyService() throws IOException {
    System.out.println("Unit Test: testListMyService()");
    JmmDNS registry = null;
    try {
        registry = JmmDNS.Factory.getInstance();
        registry.registerService(service);

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

示例7: testListenForMyServiceAndList

import javax.jmdns.JmmDNS; //导入依赖的package包/类
@Test
public void testListenForMyServiceAndList() throws IOException {
    System.out.println("Unit Test: testListenForMyServiceAndList()");
    JmmDNS 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 = JmmDNS.Factory.getInstance();
        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 JmmDNS.list.
        ServiceInfo[] services = registry.list(info.getType());
        assertTrue("We did not get the expected number of services: ", services.length > 0);
        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,代码来源:JmmDNSTest.java

示例8: newHostInfo

import javax.jmdns.JmmDNS; //导入依赖的package包/类
public static HostInfo newHostInfo(InetAddress address, JmDNSImpl dns)
{
    HostInfo localhost = null;
    try
    {
        InetAddress addr = address;
        String aName = "";
        if (addr == null)
        {
            String ip = System.getProperty("net.mdns.interface");
            if (ip != null)
            {
                addr = InetAddress.getByName(ip);
            }
            else
            {
                addr = InetAddress.getLocalHost();
                if (addr.isLoopbackAddress())
                {
                    // Find local address that isn't a loopback address
                    InetAddress[] addresses = JmmDNS.NetworkTopologyDiscovery.Factory.getInstance().getInetAddresses();
                    if (addresses.length > 0)
                    {
                        addr = addresses[0];
                    }
                }
            }
            aName = addr.getHostName();
            if (addr.isLoopbackAddress())
            {
                logger.warning("Could not find any address beside the loopback.");
            }
        }
        else
        {
            aName = addr.getHostName();
        }
        // A host name with "." is illegal. so strip off everything and append .local.
        if (aName.contains("in-addr.arpa"))
        {
            aName = "computer";
        }
        final int idx = aName.indexOf(".");
        if (idx > 0)
        {
            aName = aName.substring(0, idx);
        }
        aName += ".local.";
        localhost = new HostInfo(addr, aName, dns);
    }
    catch (final IOException e)
    {
        logger.log(Level.WARNING, "Could not intialize the host network interface on " + address + "because of an error: " + e.getMessage(), e);
        // This is only used for running unit test on Debian / Ubuntu
        localhost = new HostInfo(loopbackAddress(), "computer", dns);
    }
    return localhost;
}
 
开发者ID:blackshadowwalker,项目名称:log4j-collector,代码行数:59,代码来源:HostInfo.java

示例9: Browser

import javax.jmdns.JmmDNS; //导入依赖的package包/类
/**
 * @param mmDNS
 * @throws IOException
 */
Browser(JmmDNS mmDNS) throws IOException {
    super("JmDNS Browser");
    this.jmmdns = mmDNS;

    Color bg = new Color(230, 230, 230);
    EmptyBorder border = new EmptyBorder(5, 5, 5, 5);
    Container content = getContentPane();
    content.setLayout(new GridLayout(1, 3));

    types = new DefaultListModel();
    typeList = new JList(types);
    typeList.setBorder(border);
    typeList.setBackground(bg);
    typeList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    typeList.addListSelectionListener(this);

    JPanel typePanel = new JPanel();
    typePanel.setLayout(new BorderLayout());
    typePanel.add("North", new JLabel("Types"));
    typePanel.add("Center", new JScrollPane(typeList, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED));
    content.add(typePanel);

    services = new DefaultListModel();
    serviceList = new JList(services);
    serviceList.setBorder(border);
    serviceList.setBackground(bg);
    serviceList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    serviceList.addListSelectionListener(this);

    JPanel servicePanel = new JPanel();
    servicePanel.setLayout(new BorderLayout());
    servicePanel.add("North", new JLabel("Services"));
    servicePanel.add("Center", new JScrollPane(serviceList, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED));
    content.add(servicePanel);

    info = new JTextArea();
    info.setBorder(border);
    info.setBackground(bg);
    info.setEditable(false);
    info.setLineWrap(true);

    JPanel infoPanel = new JPanel();
    infoPanel.setLayout(new BorderLayout());
    infoPanel.add("North", new JLabel("Details"));
    infoPanel.add("Center", new JScrollPane(info, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED));
    content.add(infoPanel);

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setLocation(100, 100);
    setSize(600, 400);

    this.jmmdns.addServiceTypeListener(this);

    // register some well known types
    // String list[] = new String[] { "_http._tcp.local.", "_ftp._tcp.local.", "_tftp._tcp.local.", "_ssh._tcp.local.", "_smb._tcp.local.", "_printer._tcp.local.", "_airport._tcp.local.", "_afpovertcp._tcp.local.", "_ichat._tcp.local.",
    // "_eppc._tcp.local.", "_presence._tcp.local.", "_rfb._tcp.local.", "_daap._tcp.local.", "_touchcs._tcp.local." };
    String[] list = new String[] {};

    for (int i = 0; i < list.length; i++) {
        this.jmmdns.registerServiceType(list[i]);
    }

    this.setVisible(true);
}
 
开发者ID:josephw,项目名称:jmdns,代码行数:69,代码来源:Browser.java

示例10: main

import javax.jmdns.JmmDNS; //导入依赖的package包/类
public static void main(String argv[]) throws IOException {
    int argc = argv.length;
    boolean debug = false;
    InetAddress intf = null;

    if ((argc > 0) && "-d".equals(argv[0])) {
        System.arraycopy(argv, 1, argv, 0, --argc);

        {
            ConsoleHandler handler = new ConsoleHandler();
            handler.setLevel(Level.FINEST);
            for (Enumeration<String> enumerator = LogManager.getLogManager().getLoggerNames(); enumerator.hasMoreElements();) {
                String loggerName = enumerator.nextElement();
                Logger logger = Logger.getLogger(loggerName);
                logger.addHandler(handler);
                logger.setLevel(Level.FINEST);
            }
        }
        debug = true;
    }

    if ((argc > 1) && "-i".equals(argv[0])) {
        intf = InetAddress.getByName(argv[1]);
        System.arraycopy(argv, 2, argv, 0, argc -= 2);
    }
    if (intf == null) {
        intf = InetAddress.getLocalHost();
    }

    JmDNS jmdns = JmDNS.create(intf, "Browser");

    if ((argc == 0) || ((argc >= 1) && "-browse".equals(argv[0]))) {
        new Browser(JmmDNS.Factory.getInstance());
        for (int i = 2; i < argc; i++) {
            jmdns.registerServiceType(argv[i]);
        }
    } else if ((argc == 1) && "-bt".equals(argv[0])) {
        jmdns.addServiceTypeListener(new SampleListener());
    } else if ((argc == 3) && "-bs".equals(argv[0])) {
        jmdns.addServiceListener(argv[1] + "." + argv[2], new SampleListener());
    } else if ((argc > 4) && "-rs".equals(argv[0])) {
        String type = argv[2] + "." + argv[3];
        String name = argv[1];
        Hashtable<String, Object> props = null;
        for (int i = 5; i < argc; i++) {
            int j = argv[i].indexOf('=');
            if (j < 0) {
                throw new RuntimeException("not key=val: " + argv[i]);
            }
            if (props == null) {
                props = new Hashtable<String, Object>();
            }
            props.put(argv[i].substring(0, j), argv[i].substring(j + 1));
        }
        jmdns.registerService(ServiceInfo.create(type, name, Integer.parseInt(argv[4]), 0, 0, props));

        // This while loop keeps the main thread alive
        while (true) {
            try {
                Thread.sleep(Integer.MAX_VALUE);
            } catch (InterruptedException e) {
                break;
            }
        }
    } else if ((argc == 2) && "-f".equals(argv[0])) {
        new Responder(JmDNS.create(intf, "Responder"), argv[1]);
    } else if (!debug) {
        System.out.println();
        System.out.println("jmdns:");
        System.out.println("     -d                                       - output debugging info");
        System.out.println("     -i <addr>                                - specify the interface address");
        System.out.println("     -browse [<type>...]                      - GUI browser (default)");
        System.out.println("     -bt                                      - browse service types");
        System.out.println("     -bs <type> <domain>                      - browse services by type");
        System.out.println("     -rs <name> <type> <domain> <port> <txt>  - register service");
        System.out.println("     -f <file>                                - rendezvous responder");
        System.out.println();
        System.exit(1);
    }
}
 
开发者ID:josephw,项目名称:jmdns,代码行数:81,代码来源:Main.java

示例11: testCreate

import javax.jmdns.JmmDNS; //导入依赖的package包/类
@Test
public void testCreate() throws IOException {
    System.out.println("Unit Test: testCreate()");
    JmmDNS registry = JmmDNS.Factory.getInstance();
    registry.close();
}
 
开发者ID:josephw,项目名称:jmdns,代码行数:7,代码来源:JmmDNSTest.java

示例12: testListenForMyService

import javax.jmdns.JmmDNS; //导入依赖的package包/类
@Test
public void testListenForMyService() throws IOException {
    System.out.println("Unit Test: testListenForMyService()");
    JmmDNS registry = null;
    try {
        Capture<ServiceEvent> capServiceAddedEvent = new Capture<ServiceEvent>();
        Capture<ServiceEvent> capServiceResolvedEvent = new Capture<ServiceEvent>();
        // Add an expectation that the listener interface will be called once capture the object so I can verify it separately.
        serviceListenerMock.serviceAdded(capture(capServiceAddedEvent));
        serviceListenerMock.serviceResolved(capture(capServiceResolvedEvent));
        EasyMock.replay(serviceListenerMock);
        // EasyMock.makeThreadSafe(serviceListenerMock, false);

        registry = JmmDNS.Factory.getInstance();

        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 added service:", service.getName(), info.getName());
        assertEquals("We did not get the right type for the added service:", service.getType(), info.getType());
        assertEquals("We did not get the right fully qualified name for the added service:", service.getQualifiedName(), info.getQualifiedName());

        // assertEquals("We should not get the server for the added service:", "", info.getServer());
        // assertEquals("We should not get the address for the added service:", null, info.getAddress());
        // assertEquals("We should not get the HostAddress for the added service:", "", info.getHostAddress());
        // assertEquals("We should not get the InetAddress for the added service:", null, info.getInetAddress());
        // assertEquals("We should not get the NiceTextString for the added service:", "", info.getNiceTextString());
        // assertEquals("We should not get the Priority for the added service:", 0, info.getPriority());
        // assertFalse("We should not get the PropertyNames for the added service:", info.getPropertyNames().hasMoreElements());
        // assertEquals("We should not get the TextBytes for the added service:", 0, info.getTextBytes().length);
        // assertEquals("We should not get the TextString for the added service:", null, info.getTextString());
        // assertEquals("We should not get the Weight for the added service:", 0, info.getWeight());
        // assertNotSame("We should not get the URL for the added service:", "", info.getURL());

        registry.requestServiceInfo(service.getType(), service.getName());

        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,代码行数:50,代码来源:JmmDNSTest.java

示例13: main

import javax.jmdns.JmmDNS; //导入依赖的package包/类
/**
 * Main program.
 *
 * @param argv
 * @throws IOException
 */
public static void main(String argv[]) throws IOException {
    new Browser(JmmDNS.Factory.getInstance());
}
 
开发者ID:josephw,项目名称:jmdns,代码行数:10,代码来源:Browser.java


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