TraveSim Adapters  0.1
Protobuf adapters for TraveSim project
sender.hpp
Go to the documentation of this file.
1 /**
2  * @file sender.hpp
3  *
4  * @author Lucas Haug <lucas.haug@thuneratz.org>
5  * @author Lucas Schneider <lucas.schneider@thuneratz.org>
6  *
7  * @brief Send data using UDP
8  *
9  * @date 04/2021
10  *
11  * @copyright MIT License - Copyright (c) 2021 ThundeRatz
12  */
13 
14 #include <boost/asio.hpp>
15 #include <string>
16 
17 #ifndef __SENDER_H__
18 #define __SENDER_H__
19 
20 namespace travesim {
21 namespace udp {
22 /**
23  * @brief Sender class using UDP
24  */
25 class Sender {
26  public:
27  /**
28  * @brief Construct a new Sender object
29  *
30  * @param receiver_address Address where to send data
31  * @param receiver_port Port where to send data
32  */
33  Sender(const std::string receiver_address, const short receiver_port);
34 
35  /**
36  * @brief Destroy the Sender object
37  */
38  virtual ~Sender();
39 
40  /**
41  * @brief Send data using UDP
42  *
43  * @param buffer Buffer to be sent
44  * @param buffer_size Size of the buffer to be sent
45  *
46  * @return size_t Number of bytes sent
47  */
48  size_t send(const char* buffer, const size_t buffer_size);
49 
50  /**
51  * @brief Set the receiver endpoint object
52  *
53  * @param receiver_address Address where to send data
54  * @param receiver_port Port where to send data
55  */
56  void set_receiver_endpoint(const std::string receiver_address, const short receiver_port);
57 
58  protected:
59  boost::asio::ip::udp::socket* socket; /**< Network socket */
60  boost::asio::ip::udp::endpoint endpoint; /**< Multicast address and port pair */
61 
62  private:
63  boost::asio::io_context io_context; /**< boost/asio I/O execution context */
64 };
65 } // namespace udp
66 } // namespace travesim
67 
68 #endif // __SENDER_H__
Sender(const std::string receiver_address, const short receiver_port)
Construct a new Sender object.
Definition: sender.cpp:33
boost::asio::io_context io_context
Definition: sender.hpp:63
size_t send(const char *buffer, const size_t buffer_size)
Send data using UDP.
Definition: sender.cpp:46
virtual ~Sender()
Destroy the Sender object.
Definition: sender.cpp:40
void set_receiver_endpoint(const std::string receiver_address, const short receiver_port)
Set the receiver endpoint object.
Definition: sender.cpp:68
boost::asio::ip::udp::socket * socket
Definition: sender.hpp:59
boost::asio::ip::udp::endpoint endpoint
Definition: sender.hpp:60
Sender class using UDP.
Definition: sender.hpp:25