Asynchronous UDP socket wrapper used by the server.
More...
#include <transport/UdpTransport.hpp>
|
| | UdpTransport (asio::io_context &context, std::uint16_t port, NetworkMetrics &metrics) |
| | Opens an IPv4 UDP socket bound to a port.
|
| |
|
void | startReceive () |
| | Starts the receive loop that forwards datagrams to the callback.
|
| |
| void | send (const asio::ip::udp::endpoint &destination, const std::vector< std::uint8_t > &data) |
| | Queues a datagram for sending, ignored if larger than the limit.
|
| |
|
void | close () |
| | Cancels pending operations and closes the socket.
|
| |
| bool | isOpen () const |
| | Tells whether the socket is still open.
|
| |
| void | setReceiveCallback (std::function< void(const asio::ip::udp::endpoint &Endpoint, const std::vector< std::uint8_t > &)> callback) |
| | Sets the function called for every received datagram.
|
| |
Asynchronous UDP socket wrapper used by the server.
◆ UdpTransport()
| UdpTransport::UdpTransport |
( |
asio::io_context & | context, |
|
|
std::uint16_t | port, |
|
|
NetworkMetrics & | metrics ) |
Opens an IPv4 UDP socket bound to a port.
- Parameters
-
| context | Asio context that runs the socket handlers. |
| port | Local port to listen on. |
| metrics | Counters updated on every send and receive. |
◆ send()
| void UdpTransport::send |
( |
const asio::ip::udp::endpoint & | destination, |
|
|
const std::vector< std::uint8_t > & | data ) |
Queues a datagram for sending, ignored if larger than the limit.
- Parameters
-
| destination | Address and port of the receiver. |
| data | Bytes to send. |
◆ isOpen()
| bool UdpTransport::isOpen |
( |
| ) |
const |
Tells whether the socket is still open.
- Returns
- True if the socket is open.
◆ setReceiveCallback()
| void UdpTransport::setReceiveCallback |
( |
std::function< void(const asio::ip::udp::endpoint &Endpoint, const std::vector< std::uint8_t > &)> | callback | ) |
|
Sets the function called for every received datagram.
- Parameters
-
| callback | Receives the sender address and the datagram bytes. |