A C++ library for distributed co-simulation
Public Member Functions | List of all members
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...
 Destructor. More...
void Stop ()
 Stops broadcasting service information.

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 


[in]partitionIDThis 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]serviceTypeThe name of the service type, which may be any string of at most 255 characters. This is used to filter services in Listener.
[in]serviceIdentifierA 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]payloadA 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]payloadSizeThe size of the data payload.
[in]periodHow 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]networkInterfaceThe name or IP address of the network interface to broadcast on, or "*" to broadcast on all interfaces.
[in]portWhich UDP port to broadcast to. The Listener must use the same port.
std::runtime_erroron error.
coral::net::service::Beacon::~Beacon ( )


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: