Discovery.java
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2013 Yujin Robot.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
00005  * use this file except in compliance with the License. You may obtain a copy of
00006  * the License at
00007  *
00008  * http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00012  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
00013  * License for the specific language governing permissions and limitations under
00014  * the License.
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 //        zeroconf.addListener("_ros-master._udp","local");
00033 //        zeroconf.addListener("_concert-master._tcp","local");
00034 //        zeroconf.addListener("_concert-master._udp","local");
00035 //        zeroconf.addListener("_app-manager._tcp","local");
00036 //        zeroconf.addListener("_app-manager._udp","local");
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 }


zeroconf_jmdns_suite
Author(s): Daniel Stonier
autogenerated on Thu Aug 27 2015 15:50:26