RADLib
RADical C++ application framework
RADNet::RADUdpServer Class Reference

Convenience UDP server built on RADUdpSocket. More...

#include <RADNet.h>

+ Inheritance diagram for RADNet::RADUdpServer:
+ Collaboration diagram for RADNet::RADUdpServer:

Public Member Functions

 RADUdpServer (RADCore::EventLoop &loop)
 Creates a UDP server whose events are posted to loop. More...
 
 ~RADUdpServer ()
 Closes the internal socket. More...
 
bool listen (uint16_t port, const std::string &address="0.0.0.0")
 Starts listening for UDP datagrams on address:port. More...
 
bool sendTo (const std::string &address, uint16_t port, const std::vector< uint8_t > &payload)
 Sends payload from the server socket to address:port. More...
 
void close ()
 Stops listening and closes the socket. More...
 
uint16_t localPort () const
 Returns the bound local port, or 0 when unavailable. More...
 
void handleDatagram (RADNet::Datagram datagram)
 Internal handler that forwards datagrams from the owned socket. More...
 
void handleError (std::string message)
 Internal handler that forwards socket errors. More...
 
- Public Member Functions inherited from RADCore::RADObject
 RADObject ()
 Creates a RADObject bound to the current thread. More...
 
virtual ~RADObject ()
 Disconnects tracked event links and releases lifetime token. More...
 
void registerLink (const ConnectionRecord &record)
 Registers a connection for cleanup when this object is destroyed. More...
 
std::thread::id threadId () const
 Returns the thread id this object is currently associated with. More...
 
EventLoopassociatedEventLoop () const
 Returns the associated event loop, if any. More...
 
ThreadAffinity threadAffinity () const
 Returns both thread id and associated loop atomically. More...
 
std::weak_ptr< void > lifetimeToken () const
 Returns a weak token used to drop queued callbacks after destruction. More...
 
void moveToThread (std::thread::id tId, EventLoop *loop=nullptr)
 Moves the object's affinity to tId and optional loop. More...
 

Public Attributes

RADCore::Event< void(RADNet::Datagram) > datagramReceived
 Re-emits datagrams received by the internal socket. More...
 
RADCore::Event< void(std::string) > errorOccurred
 Re-emits socket errors from the internal socket. More...
 

Detailed Description

Convenience UDP server built on RADUdpSocket.

Constructor & Destructor Documentation

◆ RADUdpServer()

RADNet::RADUdpServer::RADUdpServer ( RADCore::EventLoop loop)
explicit

Creates a UDP server whose events are posted to loop.

◆ ~RADUdpServer()

RADNet::RADUdpServer::~RADUdpServer ( )

Closes the internal socket.

Member Function Documentation

◆ close()

void RADNet::RADUdpServer::close ( )

Stops listening and closes the socket.

◆ handleDatagram()

void RADNet::RADUdpServer::handleDatagram ( RADNet::Datagram  datagram)

Internal handler that forwards datagrams from the owned socket.

◆ handleError()

void RADNet::RADUdpServer::handleError ( std::string  message)

Internal handler that forwards socket errors.

◆ listen()

bool RADNet::RADUdpServer::listen ( uint16_t  port,
const std::string &  address = "0.0.0.0" 
)

Starts listening for UDP datagrams on address:port.

◆ localPort()

uint16_t RADNet::RADUdpServer::localPort ( ) const

Returns the bound local port, or 0 when unavailable.

◆ sendTo()

bool RADNet::RADUdpServer::sendTo ( const std::string &  address,
uint16_t  port,
const std::vector< uint8_t > &  payload 
)

Sends payload from the server socket to address:port.

Member Data Documentation

◆ datagramReceived

RADCore::Event<void (RADNet::Datagram) > RADNet::RADUdpServer::datagramReceived

Re-emits datagrams received by the internal socket.

◆ errorOccurred

RADCore::Event<void (std::string) > RADNet::RADUdpServer::errorOccurred

Re-emits socket errors from the internal socket.


The documentation for this class was generated from the following file: