57 const std::string& host,
59 std::chrono::duration<double> timeout =
73 std::uint16_t localPort,
74 std::chrono::duration<double> timeout =
99 void Send(
const std::vector<std::uint8_t>& data)
const;
106 [[nodiscard]] std::vector<std::uint8_t>
Recv(
126 void SetTimeout(std::chrono::milliseconds timeout)
override;
139 std::unique_ptr<asio::ip::udp::socket>
socket;
143 std::chrono::duration_cast<std::chrono::milliseconds>(
Abstraction for IPv4 UDP datagram transport.
Abstract interface for IPv4 UDP datagram transport.
RAII wrapper around a portable IPv4 UDP socket.
std::vector< std::uint8_t > Recv(std::size_t maxLen=defaultReceiveBufferSize) const
Receive a UDP datagram from the connected peer.
void SendTo(const std::vector< std::uint8_t > &data, const UdpEndpoint &) override
Send a datagram to a specific IPv4 endpoint.
std::chrono::milliseconds receiveTimeout
Receive timeout applied to synchronous receive operations.
void Send(const std::vector< std::uint8_t > &data) const
Send a UDP datagram to the connected peer.
std::unique_ptr< asio::io_context > ioContext
Asio execution context owned by this socket.
UdpDatagram RecvFrom(std::size_t maxLen) override
Receive a datagram together with its source endpoint.
std::unique_ptr< asio::ip::udp::socket > socket
Underlying portable Asio UDP socket.
static constexpr int defaultReceiveBufferSize
Default receive buffer size.
static constexpr double defaultTimeout
Default receive timeout in seconds.
UdpSocket & operator=(const UdpSocket &)=delete
Not copyable.
UdpSocket(const UdpSocket &)=delete
Not copyable.
UdpEndpoint LocalEndpoint() const
Return the local IPv4 endpoint assigned to the socket.
~UdpSocket() override
Destroy the socket and release all owned resources.
void SetTimeout(std::chrono::milliseconds timeout) override
Set the receive timeout used by subsequent receive operations.
A UDP datagram together with the IPv4 address of its sender.
Portable IPv4 UDP endpoint.