Class UdpSocket

Class Documentation

class UdpSocket

Wrapper around ASIO UDP socket.

Public Types

using ReceiveCallback = std::function<void(const std::vector<uint8_t>&, const std::string &remote_ip, const uint32_t remote_port)>

Public Functions

UdpSocket(const IoContext &ctx, const std::string &remote_ip, uint16_t remote_port, const std::string &host_ip, uint16_t host_port)

Construct a new UdpSocket object.

Parameters:
  • ctx – Threading context

  • remote_ip – Remote IP to receive / send data from / to

  • remote_port – Remote port

  • host_ip – Host IP (empty to use any interface)

  • host_port – Host port

~UdpSocket()

Destroy the UdpSocket object.

UdpSocket(const UdpSocket&) = delete
UdpSocket &operator=(const UdpSocket&) = delete
std::string remote_ip() const
uint16_t remote_port() const
std::string host_ip() const
uint16_t host_port() const
std::string source_ip() const
uint16_t source_port() const
void open()
void close()
bool isOpen() const
void bind()
void connect()
std::size_t send(std::vector<uint8_t> &buff)

Blocking send operation.

size_t receive(std::vector<uint8_t> &buff)

Blocking receive operation.

void asyncSend(std::vector<uint8_t> &buff)

Non-blocking send operation.

void asyncReceive(ReceiveCallback func)

Non-blocking receive operation.