cubos::core::net::UdpSocket class

Represents a UDP socket.

Constructors, destructors, conversion operators

UdpSocket()
Constructs a UDP socket.
~UdpSocket()
Deconstructs by unbinding the inner socket.
UdpSocket(const UdpSocket&) deleted
Forbid copy construction.

Public functions

auto operator=(const UdpSocket&) -> UdpSocket& deleted
Forbid copy assignment.
auto bind(uint16_t port, const Address& address = Address::Any) const -> bool
Binds a UDP socket from the given port and address.
void unbind()
Closes the inner socket.
auto send(const void* data, std::size_t size, const Address& address, uint16_t port) const -> bool
Sends data on the socket to the remote address and port.
auto receive(void* data, std::size_t size, std::size_t& received, Address& address) const -> bool
Receives a single datagram message on the socket.
auto setBlocking(bool blocking) -> bool
Control blocking mode of inner socket.

Function documentation

bool cubos::core::net::UdpSocket::bind(uint16_t port, const Address& address = Address::Any) const

Binds a UDP socket from the given port and address.

Parameters
port Port to bind.
address Address to bind.
Returns Whether binding was successful.

bool cubos::core::net::UdpSocket::send(const void* data, std::size_t size, const Address& address, uint16_t port) const

Sends data on the socket to the remote address and port.

Parameters
data Message.
size Message size.
address Address to send.
port Port to send.
Returns Whether data was sent sucessfully.

bool cubos::core::net::UdpSocket::receive(void* data, std::size_t size, std::size_t& received, Address& address) const

Receives a single datagram message on the socket.

Parameters
data Buffer to store the datagram message.
size Maximum buffer size.
received out Number of bytes read.
address out Origin address.
Returns Whether data was received sucessfully.

bool cubos::core::net::UdpSocket::setBlocking(bool blocking)

Control blocking mode of inner socket.

Parameters
blocking Whether to block or not.
Returns Whether setting the block flag was sucessfull.