betabugs::networking::service_discoverer Class Reference
#include <service_discoverer.hpp>
Classes | |
struct | service |
Public Types | |
typedef std::set< service > | services |
a set of discovered services | |
typedef std::function< void(const services &services)> | on_services_changed_t |
this callback gets called, when ever the set of available services changes | |
Public Member Functions | |
service_discoverer (boost::asio::io_service &io_service, const std::string &listen_for_service, const on_services_changed_t on_services_changed, const std::chrono::steady_clock::duration max_idle=std::chrono::seconds(30), const size_t max_services=10, const unsigned short multicast_port=30001, const boost::asio::ip::address &listen_address=boost::asio::ip::address::from_string("0.0.0.0"), const boost::asio::ip::address &multicast_address=boost::asio::ip::address::from_string("239.255.0.1")) | |
Detailed Description
Class to discover services announced by the service_announcer use service_discoverer discoverer(io_service, name_of_my_service, on_service_discovered); on_service_discovered is a std::function, that gets a services set passed as its first and only argument.
example:
boost::asio::io_service io_service;
service_discoverer discoverer(
io_service,
"my_awesome_service",
{
for(auto& service : services)
{
std::cout << "discovered: " service << std::endl;
}
}
);
io_service.run();
Note: In case of error, this class just prints to std::cerr
Constructor & Destructor Documentation
|
inline |
Constructs a service_discoverer.
listen for udp multicast packets announcing listen_for_service on listen_address:multicast_port.
Call on_services_changed each time a service has been discovered or a service has been idle for too long. To protect against malicious announcers, there is a limit (max_services) on how many services will end up in the set of discovered services.
- Parameters
-
io_service io_service to use listen_for_service the service to watch out for on_services_changed gets called when ever the set of discovered services changes max_idle services not seen for this amount of time will be removed from the set max_services maximum number of services to hold multicast_port the udp multicast port to listen on listen_address address to listen on multicast_address must match the one used in service_announcer
The documentation for this class was generated from the following file: