Skip to content

AUdpSocket#

A bidirectional UDP socket.

Header:#include <AUI/Network/AUdpSocket.h>
CMake:aui_link(my_target PUBLIC aui::network)

Detailed Description#

UDP is connectionless: every write sends one datagram to an explicit destination and every read receives one datagram along with the sender's address. Delivery and ordering are not guaranteed.

AUdpSocket socket(9000);          // receiver, bound to port 9000
AByteBuffer buffer;
AInet4Address sender;
socket.read(buffer, sender);      // blocks until a datagram arrives
socket.write(buffer, sender);     // reply

The datagram size is limited to 32767 bytes. See UDP datagrams and ping.

Public Methods#

constructor#


AUdpSocket::AUdpSocket(uint16_t port)

Creates socket

Arguments
port
port

AUdpSocket::AUdpSocket()

Creates socket with random port (used for "client" socket)

read#


void AUdpSocket::read(AByteBuffer& buf, AInet4Address& dst)

Read data.

Arguments
buf
(out) received data
dst
(out) sender address

write#


void AUdpSocket::write(AByteBufferView buf, const AInet4Address& dst)

Sends data by address.

Arguments
buf
data buffer
dst
destination delivery address