Agora  1.2.0
Agora project
UDPServer Class Reference

Basic UDP server class based on OS sockets that supports receiving messages. More...

#include <udp_server.h>

Collaboration diagram for UDPServer:

Public Member Functions

 UDPServer (std::string local_address, uint16_t local_port, size_t rx_buffer_size=0)
 
 UDPServer (std::string local_address, std::string local_port, size_t rx_buffer_size=0)
 
UDPServeroperator= (const UDPServer &)=delete
 
 UDPServer (const UDPServer &)=delete
 
 ~UDPServer ()=default
 
ssize_t Connect (const std::string &remote_address, const std::string &remote_port)
 The remote_address | remote_port is the only address to which datagrams are received. 1:1 association remote<-me. More...
 
ssize_t Connect (const std::string &remote_address, uint16_t remote_port)
 
ssize_t Recv (std::byte *buf, size_t len) const
 Try to receive up to len bytes in buf by default this will not block. More...
 
ssize_t Recv (const std::string &src_address, uint16_t src_port, std::byte *buf, size_t len)
 
void MakeBlocking (size_t timeout_sec=0) const
 Configures the socket in blocking mode. Any calls to recv / send will now block. More...
 
const std::string & Address () const
 
const std::string & Port () const
 

Private Attributes

const std::string address_
 The UDP port to server is listening on. More...
 
const std::string port_
 
UDPComm comm_object_
 

Detailed Description

Basic UDP server class based on OS sockets that supports receiving messages.

Constructor & Destructor Documentation

◆ UDPServer() [1/3]

UDPServer::UDPServer ( std::string  local_address,
uint16_t  local_port,
size_t  rx_buffer_size = 0 
)
inlineexplicit

◆ UDPServer() [2/3]

UDPServer::UDPServer ( std::string  local_address,
std::string  local_port,
size_t  rx_buffer_size = 0 
)
inlineexplicit

◆ UDPServer() [3/3]

UDPServer::UDPServer ( const UDPServer )
delete

◆ ~UDPServer()

UDPServer::~UDPServer ( )
default

Member Function Documentation

◆ Address()

const std::string& UDPServer::Address ( ) const
inline

◆ Connect() [1/2]

ssize_t UDPServer::Connect ( const std::string &  remote_address,
const std::string &  remote_port 
)
inline

The remote_address | remote_port is the only address to which datagrams are received. 1:1 association remote<-me.

Parameters
remote_addressHostname or IP address of the remote server
remote_portUDP port of the remote server
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Connect() [2/2]

ssize_t UDPServer::Connect ( const std::string &  remote_address,
uint16_t  remote_port 
)
inline
Here is the call graph for this function:

◆ MakeBlocking()

void UDPServer::MakeBlocking ( size_t  timeout_sec = 0) const
inline

Configures the socket in blocking mode. Any calls to recv / send will now block.

Here is the call graph for this function:

◆ operator=()

UDPServer& UDPServer::operator= ( const UDPServer )
delete

◆ Port()

const std::string& UDPServer::Port ( ) const
inline

◆ Recv() [1/2]

ssize_t UDPServer::Recv ( const std::string &  src_address,
uint16_t  src_port,
std::byte *  buf,
size_t  len 
)
inline
Here is the call graph for this function:

◆ Recv() [2/2]

ssize_t UDPServer::Recv ( std::byte *  buf,
size_t  len 
) const
inline

Try to receive up to len bytes in buf by default this will not block.

Returns
Return the number of bytes received if non-zero bytes are received. If no bytes are received, return zero. If there was an error in receiving, return -1.
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ address_

const std::string UDPServer::address_
private

The UDP port to server is listening on.

◆ comm_object_

UDPComm UDPServer::comm_object_
private

◆ port_

const std::string UDPServer::port_
private

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