TraveSim Adapters  0.1
Protobuf adapters for TraveSim project
travesim::udp::MulticastReceiver Class Reference

Receiver class using UDP in multicast mode. More...

#include "multicast_receiver.hpp"

Inheritance diagram for travesim::udp::MulticastReceiver:
Collaboration diagram for travesim::udp::MulticastReceiver:

Public Member Functions

 MulticastReceiver (const std::string multicast_address, const short multicast_port, const std::string receiver_address)
 Construct a new Multicast Receiver object. More...
 
 MulticastReceiver (const std::string multicast_address, const short multicast_port)
 Construct a new Multicast Receiver object. More...
 
 ~MulticastReceiver ()
 Destroy the Multicast Receiver object. More...
 
void set_multicast_address (const std::string multicast_address)
 Set the multicast address. More...
 
- Public Member Functions inherited from travesim::udp::Receiver
 Receiver (const std::string receiver_address, const short receiver_port)
 Construct a new Receiver object. More...
 
virtual ~Receiver ()
 Destroy the Receiver object. More...
 
size_t receive (char *buffer, const size_t buffer_size)
 Receive data using UDP. More...
 
size_t receive_latest (char *buffer, const size_t buffer_size)
 Receive the latest data using UDP. More...
 
void force_specific_source (bool specific_source)
 Set wheter to enable any source or source specific. True for specific source, false for any source, default is false. More...
 
void set_receiver_endpoint (const std::string receiver_address, const short receiver_port)
 Set the receiver endpoint. More...
 
void reset (void)
 Reset the receiver. More...
 

Private Member Functions

void open_socket ()
 Open the socket with the desired options. More...
 
void close_socket ()
 Close the socket. More...
 

Private Attributes

boost::asio::ip::address multicast_address
 

Additional Inherited Members

- Protected Attributes inherited from travesim::udp::Receiver
boost::asio::ip::udp::socket * socket
 
boost::asio::ip::udp::endpoint receiver_endpoint
 

Detailed Description

Receiver class using UDP in multicast mode.

Definition at line 24 of file multicast_receiver.hpp.

Constructor & Destructor Documentation

◆ MulticastReceiver() [1/2]

travesim::udp::MulticastReceiver::MulticastReceiver ( const std::string  multicast_address,
const short  multicast_port,
const std::string  receiver_address 
)

Construct a new Multicast Receiver object.

Parameters
multicast_addressMulticas group address
multicast_portMulticast group port
receiver_addressReceiver address, has a filtering role, setting where the data may be received
Note
The multicast addresses must be in the range 224.0.0.0 through 239.255.255.255, see IPv4 Multicast Address Space Registry or the RFC1112 for more informations.

Definition at line 22 of file multicast_receiver.cpp.

23  : Receiver(receiver_address, multicast_port) {
25 
26  this->open_socket();
27 };
void set_multicast_address(const std::string multicast_address)
Set the multicast address.
boost::asio::ip::address multicast_address
Receiver(const std::string receiver_address, const short receiver_port)
Construct a new Receiver object.
Definition: receiver.cpp:32
void open_socket()
Open the socket with the desired options.

References open_socket(), and set_multicast_address().

Here is the call graph for this function:

◆ MulticastReceiver() [2/2]

travesim::udp::MulticastReceiver::MulticastReceiver ( const std::string  multicast_address,
const short  multicast_port 
)

Construct a new Multicast Receiver object.

Parameters
multicast_addressMulticas group address
multicast_portMulticast group port
Note
Use multicast address as listen address
The multicast addresses must be in the range 224.0.0.0 through 239.255.255.255, see IPv4 Multicast Address Space Registry or the RFC1112 for more informations.

Definition at line 29 of file multicast_receiver.cpp.

29  :
31 };
MulticastReceiver(const std::string multicast_address, const short multicast_port, const std::string receiver_address)
Construct a new Multicast Receiver object.
boost::asio::ip::address multicast_address

◆ ~MulticastReceiver()

travesim::udp::MulticastReceiver::~MulticastReceiver ( )

Destroy the Multicast Receiver object.

Definition at line 33 of file multicast_receiver.cpp.

33  {
34  this->close_socket();
35 };
void close_socket()
Close the socket.

References close_socket().

Here is the call graph for this function:

Member Function Documentation

◆ close_socket()

void travesim::udp::MulticastReceiver::close_socket ( )
privatevirtual

Close the socket.

Reimplemented from travesim::udp::Receiver.

Definition at line 62 of file multicast_receiver.cpp.

62  {
63  if (this->socket->is_open()) {
64  this->socket->set_option(boost::asio::ip::multicast::leave_group(this->multicast_address));
65  this->socket->close();
66  }
67 };
boost::asio::ip::udp::socket * socket
Definition: receiver.hpp:88
boost::asio::ip::address multicast_address

References multicast_address, and travesim::udp::Receiver::socket.

Here is the caller graph for this function:

◆ open_socket()

void travesim::udp::MulticastReceiver::open_socket ( )
privatevirtual

Open the socket with the desired options.

Implements travesim::udp::Receiver.

Definition at line 46 of file multicast_receiver.cpp.

46  {
47  // Create the socket so that multiple may be bound to the same address.
48  this->socket->open(this->receiver_endpoint.protocol());
49 
50  this->socket->set_option(boost::asio::ip::udp::socket::reuse_address(true));
51  this->socket->set_option(boost::asio::ip::multicast::hops(1));
52 
53  // Join the multicast group.
54  this->socket->set_option(boost::asio::ip::multicast::join_group(this->multicast_address));
55 
56  this->socket->bind(this->receiver_endpoint);
57 
58  // Use non blocking for syncronous reading
59  this->socket->non_blocking(true);
60 };
boost::asio::ip::udp::socket * socket
Definition: receiver.hpp:88
boost::asio::ip::udp::endpoint receiver_endpoint
Definition: receiver.hpp:89
boost::asio::ip::address multicast_address

References multicast_address, travesim::udp::Receiver::receiver_endpoint, and travesim::udp::Receiver::socket.

Here is the caller graph for this function:

◆ set_multicast_address()

void travesim::udp::MulticastReceiver::set_multicast_address ( const std::string  multicast_address)

Set the multicast address.

Parameters
multicast_addressMulticast group address in a string
Warning
reset() must be called after changing the address
Note
The multicast addresses must be in the range 224.0.0.0 through 239.255.255.255, see IPv4 Multicast Address Space Registry or the RFC1112 for more informations.

Definition at line 37 of file multicast_receiver.cpp.

37  {
38  const boost::asio::ip::address multicast_boost_addr = boost::asio::ip::address::from_string(multicast_address);
39  this->multicast_address = multicast_boost_addr;
40 };
boost::asio::ip::address multicast_address

References multicast_address.

Here is the caller graph for this function:

Member Data Documentation

◆ multicast_address

boost::asio::ip::address travesim::udp::MulticastReceiver::multicast_address
private

Definition at line 78 of file multicast_receiver.hpp.


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