UDP socket. More...
#include <udpSocket.hpp>
Public Member Functions | |
| UdpSocket (const std::string &host="", uint16_t port=0) | |
| void | sendTo (std::string_view data, const anch::network::Address &to) |
| void | sendTo (std::string_view data, const std::string &host, uint16_t port) |
| anch::network::Address | receiveFrom (std::string &data, std::size_t maxSize=MAX_DATAGRAM_SIZE) |
| anch::network::Address | getAddress () const |
| anch::network::Socket & | getSocket () noexcept |
Static Public Attributes | |
| static constexpr std::size_t | MAX_DATAGRAM_SIZE = 65507 |
UDP socket.
Datagrams keep their boundaries and can contain any byte ('\0' included). A datagram which does not fit in the reception buffer raises IOException (EMSGSIZE ) instead of being silently truncated.
|
explicit |
UdpSocket constructor: bind to local address
| host | the local host name or numeric address (empty for any address) |
| port | the local port (0 for an ephemeral port: see getAddress ) |
| anch::network::IOException | bind error |
| anch::network::Address anch::network::UdpSocket::getAddress | ( | ) | const |
Local address getter (useful for ephemeral port)
| anch::network::IOException | error on getsockname |
|
noexcept |
Socket getter (for options, timeouts, ...)
| anch::network::Address anch::network::UdpSocket::receiveFrom | ( | std::string & | data, |
| std::size_t | maxSize = MAX_DATAGRAM_SIZE ) |
Receive a datagram
| data | receives the datagram |
| maxSize | the maximum datagram size |
| anch::network::IOException | reception error, or datagram larger than maxSize (EMSGSIZE ) |
| void anch::network::UdpSocket::sendTo | ( | std::string_view | data, |
| const anch::network::Address & | to ) |
Send a datagram
| data | the datagram |
| to | the destination |
| anch::network::IOException | send error (or datagram not entirely sent) |
| void anch::network::UdpSocket::sendTo | ( | std::string_view | data, |
| const std::string & | host, | ||
| uint16_t | port ) |
Send a datagram (the destination is resolved for the socket address family)
| data | the datagram |
| host | the destination host name or numeric address |
| port | the destination port |
| anch::network::IOException | resolution or send error |
|
staticconstexpr |
Maximum UDP payload (IPv4)