TraveSim Adapters  0.1
Protobuf adapters for TraveSim project
multicast_sender_example.cpp File Reference

Example on how to use the MulticastSender. More...

#include <boost/asio.hpp>
#include <iostream>
#include <string>
#include "travesim_adapters/udp/multicast_sender.hpp"
Include dependency graph for multicast_sender_example.cpp:

Go to the source code of this file.

Functions

int main ()
 

Detailed Description

Example on how to use the MulticastSender.

Author
Lucas Haug lucas.nosp@m..hau.nosp@m.g@thu.nosp@m.nera.nosp@m.tz.or.nosp@m.g
Lucas Schneider lucas.nosp@m..sch.nosp@m.neide.nosp@m.r@th.nosp@m.unera.nosp@m.tz.o.nosp@m.rg
Date
04/2021

Definition in file multicast_sender_example.cpp.

Function Documentation

◆ main()

int main ( )

Definition at line 24 of file multicast_sender_example.cpp.

24  {
25  const std::string multicast_address_str = "224.0.0.1";
26  const short multicast_port = 10002;
27  const int max_message_count = 10;
28 
29  try {
30  boost::asio::io_context io_context;
31  boost::asio::steady_timer my_timer(io_context);
32  travesim::udp::MulticastSender my_sender(multicast_address_str, multicast_port);
33 
34  for (int i = 0; i < max_message_count; i++) {
35  std::string msg = "Menssagem " + std::to_string(i);
36  size_t bytes_sent = my_sender.send(msg.c_str(), msg.length());
37 
38  std::cout << msg << "\nBytes sent: " << bytes_sent << "\n\n";
39 
40  my_timer.expires_after(std::chrono::milliseconds(200));
41  my_timer.wait();
42  }
43  } catch (std::exception& e) {
44  std::cerr << "Exception: " << e.what() << "\n";
45  }
46 
47  return 0;
48 }
Sender class using UDP in multicast mode.

References travesim::udp::Sender::send().

Here is the call graph for this function: