coral A C++ library for distributed co-simulation
coral::net::service::Beacon Class Reference

A class for broadcasting information about a service, so it can be automatically detected on a network. More...

#include "coral/net/service.hpp"

## Public Member Functions

Beacon (std::uint32_t partitionID, const std::string &serviceType, const std::string &serviceIdentifier, const char *payload, std::size_t payloadSize, std::chrono::milliseconds period, const ip::Address &networkInterface, ip::Port port)
Constructor. More...

~Beacon () CORAL_NOEXCEPT
Destructor. More...

void Stop ()

## Detailed Description

A class for broadcasting information about a service, so it can be automatically detected on a network.

An object of this class will start broadcasting information about its service immediately upon construction. This happens in a background thread. It is a good idea to always call Stop() before the object is destroyed, so that errors are handled properly. (See ~Beacon() for more information.)

To detect services that are announced with this class, use Listener.

## Constructor & Destructor Documentation

 coral::net::service::Beacon::Beacon ( std::uint32_t partitionID, const std::string & serviceType, const std::string & serviceIdentifier, const char * payload, std::size_t payloadSize, std::chrono::milliseconds period, const ip::Address & networkInterface, ip::Port port )

Constructor.

Parameters
 [in] partitionID This represents a way to divide the services on the same physical network into distinct partitions. A Listener will only detect services whose Beacon uses the same partitionID. [in] serviceType The name of the service type, which may be any string of at most 255 characters. This is used to filter services in Listener. [in] serviceIdentifier A name which identifies a particular service-providing entity. Its length may be up to 255 characters. Normally, this will be a unique name, at least in the context of a particular service in a particular network partition. [in] payload A service-specific data payload. If payloadSize is zero, this parameter is ignored. Otherwise, it must point to an array of size at least payloadSize. It is generally recommended that this payload be less than 1000 bytes, preferably as small as possible. (This has to do with the fact that UDP is used as the underlying protocol, and smaller messages make for more reliable delivery.) [in] payloadSize The size of the data payload. [in] period How often the service is announced on the network. A smaller period generally leads to faster detection, but also causes more network traffic. 1 second is often a good tradeoff for many application. [in] networkInterface The name or IP address of the network interface to broadcast on, or "*" to broadcast on all interfaces. [in] port Which UDP port to broadcast to. The Listener must use the same port.
Exceptions
 std::runtime_error on error.
 coral::net::service::Beacon::~Beacon ( )

Destructor.

The destructor will call Stop() if this hasn't been done already, and if that function throws, std::terminate() will be called (because the destructor is noexcept). It may therefore be a good idea to call Stop() manually before destruction, so that errors may be handled properly.

The documentation for this class was generated from the following file: