Go to the documentation of this file.00001
00013
00014
00015
00016
00017 #include <zeroconf_avahi/zeroconf.hpp>
00018 #include <zeroconf_msgs/PublishedService.h>
00019
00020
00021
00022
00023
00024 int main(int argc, char **argv) {
00025
00026 zeroconf_avahi::Zeroconf zeroconf;
00027 zeroconf_msgs::PublishedService service_dudette, service_dude, service_colliding_dude, service_not_advertised;
00028 service_dudette.name = "Dudette";
00029 service_dudette.type = "_ros-master._tcp";
00030 service_dudette.port = 8888;
00031 service_dudette.domain = "local";
00032 ROS_INFO("===== Adding a service =====");
00033 zeroconf.add_service(service_dudette);
00034 sleep(2);
00035 ROS_INFO("===== Adding a listener =====");
00036 zeroconf.add_listener(service_dudette.type);
00037 sleep(2);
00038 service_dude = service_dudette;
00039 service_dude.name = "Dude";
00040 service_dude.port = 8889;
00041 ROS_INFO("===== Adding another service =====");
00042 zeroconf.add_service(service_dude);
00043 sleep(2);
00044 ROS_INFO("===== Accidentally adding the service again =====");
00045 zeroconf.add_service(service_dude);
00046 sleep(2);
00047 service_colliding_dude = service_dude;
00048
00049 ROS_INFO("===== Local Collision =====");
00050 service_colliding_dude.port = 8890;
00051 zeroconf.add_service(service_colliding_dude);
00052 sleep(3);
00053 ROS_INFO("===== Removing some services =====");
00054 zeroconf.remove_service(service_dudette);
00055 zeroconf.remove_service(service_colliding_dude);
00056 service_not_advertised = service_dude;
00057 service_not_advertised.name = "OtherDude";
00058 ROS_INFO("===== Remove a non-advertised service =====");
00059 zeroconf.remove_service(service_not_advertised);
00060 ROS_INFO("===== Waiting for listener to detect removals =====");
00061 sleep(2);
00062 ROS_INFO("===== Remove a listener =====");
00063 zeroconf.remove_listener(service_dudette.type);
00064 return 0;
00065 }