Agora  1.2.0
Agora project
udp_client.h
Go to the documentation of this file.
1 
5 #ifndef UDP_CLIENT_H_
6 #define UDP_CLIENT_H_
7 
8 #include <utility>
9 
10 #include "udp_comm.h"
11 
12 // Basic UDP client class based on OS sockets that supports sending messages
13 class UDPClient {
14  public:
15  explicit UDPClient(const std::string& src_addr, uint16_t src_port,
16  size_t tx_buffer_size = 0)
17  : comm_object_(src_addr, src_port, 0, tx_buffer_size) {}
18  explicit UDPClient(uint16_t src_port)
19  : comm_object_(std::string(), src_port, 0, 0) {}
20  explicit UDPClient(const std::string& src_addr)
21  : comm_object_(src_addr, 0, 0, 0) {}
22 
23  UDPClient& operator=(const UDPClient&) = delete;
24  UDPClient(const UDPClient&) = delete;
25  ~UDPClient() = default;
26 
34  inline ssize_t Connect(const std::string& remote_address,
35  uint16_t remote_port) {
36  return comm_object_.Connect(remote_address, remote_port);
37  };
38 
50  inline void Send(const std::string& rem_hostname, uint16_t rem_port,
51  const std::byte* msg, size_t len) {
52  return comm_object_.Send(rem_hostname, rem_port, msg, len);
53  }
54 
61  inline void Send(const std::byte* msg, size_t len) {
62  return comm_object_.Send(msg, len);
63  }
64 
65  // Enable recording of all packets sent by this UDP client
66  inline void EnableRecording() { return comm_object_.EnableRecording(); }
67 
68  private:
70 };
71 
72 #endif // UDP_CLIENT_H_
fmt::v8::detail::byte
byte
Definition: core.h:388
udp_comm.h
Declaration file for the UDPComm class. This class is used to send messages and receive messages from...
UDPComm
Definition: udp_comm.h:18
src_port
uint16_t src_port
Definition: eth_common.h:60
UDPClient::UDPClient
UDPClient(const std::string &src_addr)
Definition: udp_client.h:20
UDPClient::UDPClient
UDPClient(const std::string &src_addr, uint16_t src_port, size_t tx_buffer_size=0)
Definition: udp_client.h:15
UDPClient::Connect
ssize_t Connect(const std::string &remote_address, uint16_t remote_port)
The remote_address | remote_port is the address to which datagrams are sent. 1:1 association me->remo...
Definition: udp_client.h:34
UDPClient::operator=
UDPClient & operator=(const UDPClient &)=delete
UDPClient::Send
void Send(const std::byte *msg, size_t len)
Send one UDP packet to the connected remote server.
Definition: udp_client.h:61
UDPClient::comm_object_
UDPComm comm_object_
Definition: udp_client.h:69
len
uint16_t len
Definition: eth_common.h:62
UDPClient::UDPClient
UDPClient(uint16_t src_port)
Definition: udp_client.h:18
UDPComm::Connect
ssize_t Connect(const std::string &remote_address, uint16_t remote_port) const
The remote_address | remote_port is the address to which datagrams are sent. 1:1 association me<->rem...
Definition: udp_comm.cc:250
UDPClient::Send
void Send(const std::string &rem_hostname, uint16_t rem_port, const std::byte *msg, size_t len)
Send one UDP packet to a remote server. The client caches the the remote server's addrinfo after reso...
Definition: udp_client.h:50
UDPClient::~UDPClient
~UDPClient()=default
UDPComm::EnableRecording
void EnableRecording()
Definition: udp_comm.h:79
std
Definition: json.hpp:5213
UDPClient::EnableRecording
void EnableRecording()
Definition: udp_client.h:66
UDPClient
Definition: udp_client.h:13
UDPComm::Send
void Send(const std::string &rem_hostname, uint16_t rem_port, const std::byte *msg, size_t len)
Send one UDP packet to a remote server. The client caches the the remote server's addrinfo after reso...
Definition: udp_comm.cc:270