Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 package com.github.rosjava.zeroconf_jmdns_suite.jmdns.tutorials;
00017 
00018 import java.io.IOException;
00019 import java.util.List;
00020 
00021 import com.github.rosjava.zeroconf_jmdns_suite.jmdns.DiscoveredService;
00022 import com.github.rosjava.zeroconf_jmdns_suite.jmdns.StandardLogger;
00023 import com.github.rosjava.zeroconf_jmdns_suite.jmdns.Zeroconf;
00024 
00025 public class Discovery {
00026         
00027         public static void main_handler() throws IOException {
00028         Zeroconf zeroconf = new Zeroconf(new StandardLogger());
00029         DiscoveryHandler listener = new DiscoveryHandler();
00030                 zeroconf.setDefaultDiscoveryCallback(listener);
00031         zeroconf.addListener("_ros-master._tcp","local");
00032 
00033 
00034 
00035 
00036 
00037         while(true) {
00038                 try {
00039                         Thread.sleep(1000L);
00040                     } catch (InterruptedException e) {
00041                         e.printStackTrace();
00042                     }
00043         }
00044     }
00045 
00046     public static void main_polling() throws IOException {
00047         Zeroconf browser = new Zeroconf(new StandardLogger());
00048         browser.addListener("_ros-master._tcp","local");
00049         int i = 0;
00050         while( i < 8 ) {
00051                 try {
00052                         List<DiscoveredService> discovered_services = browser.listDiscoveredServices();
00053                         if ( discovered_services.size() > 0 ) {
00054                                 System.out.println("************ Discovered Services ************");
00055                                 for ( DiscoveredService discovered_service : discovered_services ) {
00056                                         browser.display(discovered_service);
00057                                 }
00058                         } else {
00059                                 System.out.println("Waiting for resolvers...");
00060                         }
00061                         Thread.sleep(1000L);
00062                     } catch (InterruptedException e) {
00063                         e.printStackTrace();
00064                     }
00065                 ++i;
00066         }
00067         browser.removeListener("_ros-master._tcp","local");
00068         browser.shutdown();
00069     }
00070 
00071 
00072 }