Network System 0.1.1
High-performance modular networking library for scalable client-server applications
Loading...
Searching...
No Matches
kcenon::network::interfaces::i_udp_server Interface Referenceabstract

Interface for UDP server components. More...

#include <i_udp_server.h>

Inheritance diagram for kcenon::network::interfaces::i_udp_server:
Inheritance graph
Collaboration diagram for kcenon::network::interfaces::i_udp_server:
Collaboration graph

Public Types

using endpoint_info = i_udp_client::endpoint_info
 Reuse endpoint_info from i_udp_client.
 
using receive_callback_t
 Callback type for received data (includes sender endpoint)
 
using error_callback_t = std::function<void(std::error_code)>
 Callback type for errors.
 
using send_callback_t = std::function<void(std::error_code, std::size_t)>
 Callback type for send completion.
 

Public Member Functions

virtual auto start (uint16_t port) -> VoidResult=0
 Starts the UDP server on the specified port.
 
virtual auto stop () -> VoidResult=0
 Stops the UDP server.
 
virtual auto send_to (const endpoint_info &endpoint, std::vector< uint8_t > &&data, send_callback_t handler=nullptr) -> VoidResult=0
 Sends a datagram to the specified endpoint.
 
virtual auto set_receive_callback (receive_callback_t callback) -> void=0
 Sets the callback for received datagrams.
 
virtual auto set_error_callback (error_callback_t callback) -> void=0
 Sets the callback for errors.
 
- Public Member Functions inherited from kcenon::network::interfaces::i_network_component
virtual ~i_network_component ()=default
 Virtual destructor for proper cleanup of derived classes.
 
 i_network_component (const i_network_component &)=delete
 
i_network_componentoperator= (const i_network_component &)=delete
 
 i_network_component (i_network_component &&)=delete
 
i_network_componentoperator= (i_network_component &&)=delete
 

Additional Inherited Members

- Protected Member Functions inherited from kcenon::network::interfaces::i_network_component
 i_network_component ()=default
 Default constructor (only for derived classes)
 
virtual auto is_running () const -> bool=0
 Checks if the component is currently running.
 
virtual auto wait_for_stop () -> void=0
 Blocks until the component has stopped.
 

Detailed Description

Interface for UDP server components.

This interface extends i_network_component with UDP server-specific operations such as receiving datagrams from multiple clients and sending responses to specific endpoints.

Key Characteristics

  • Connectionless: No client session management required
  • Endpoint-aware: Each received datagram includes sender information
  • Bidirectional: Can send responses to any endpoint

Thread Safety

  • All public methods must be thread-safe
  • Callbacks may be invoked from I/O threads
See also
i_server

Definition at line 39 of file i_udp_server.h.

Member Typedef Documentation

◆ endpoint_info

◆ error_callback_t

using kcenon::network::interfaces::i_udp_server::error_callback_t = std::function<void(std::error_code)>

Callback type for errors.

Definition at line 51 of file i_udp_server.h.

◆ receive_callback_t

Initial value:
std::function<void(
const std::vector<uint8_t>&,
const endpoint_info&)>
i_udp_client::endpoint_info endpoint_info
Reuse endpoint_info from i_udp_client.

Callback type for received data (includes sender endpoint)

Definition at line 46 of file i_udp_server.h.

◆ send_callback_t

using kcenon::network::interfaces::i_udp_server::send_callback_t = std::function<void(std::error_code, std::size_t)>

Callback type for send completion.

Definition at line 54 of file i_udp_server.h.

Member Function Documentation

◆ send_to()

virtual auto kcenon::network::interfaces::i_udp_server::send_to ( const endpoint_info & endpoint,
std::vector< uint8_t > && data,
send_callback_t handler = nullptr ) -> VoidResult
nodiscardpure virtual

Sends a datagram to the specified endpoint.

Parameters
endpointThe target endpoint.
dataThe data to send.
handlerOptional completion handler.
Returns
VoidResult indicating success or failure.

Thread Safety

Thread-safe. Multiple sends may be queued.

Implemented in kcenon::network::core::messaging_udp_server, and kcenon::network::core::unified_udp_messaging_server< TlsPolicy >.

◆ set_error_callback()

virtual auto kcenon::network::interfaces::i_udp_server::set_error_callback ( error_callback_t callback) -> void
pure virtual

Sets the callback for errors.

Parameters
callbackThe callback function.

Implemented in kcenon::network::core::messaging_udp_server, and kcenon::network::core::unified_udp_messaging_server< TlsPolicy >.

◆ set_receive_callback()

virtual auto kcenon::network::interfaces::i_udp_server::set_receive_callback ( receive_callback_t callback) -> void
pure virtual

Sets the callback for received datagrams.

Parameters
callbackThe callback function.

Note

The callback receives both the data and the sender's endpoint information, allowing responses to be sent using send_to().

Implemented in kcenon::network::core::messaging_udp_server, and kcenon::network::core::unified_udp_messaging_server< TlsPolicy >.

◆ start()

virtual auto kcenon::network::interfaces::i_udp_server::start ( uint16_t port) -> VoidResult
nodiscardpure virtual

Starts the UDP server on the specified port.

Parameters
portThe port number to bind to.
Returns
VoidResult indicating success or failure.

Behavior

  • Creates a UDP socket and binds to the specified port
  • Begins listening for incoming datagrams

Error Conditions

  • Returns error if already running
  • Returns error if socket creation fails
  • Returns error if port binding fails

Thread Safety

Thread-safe. Only one start operation can succeed at a time.

Implemented in kcenon::network::core::messaging_udp_server, and kcenon::network::core::unified_udp_messaging_server< TlsPolicy >.

◆ stop()

virtual auto kcenon::network::interfaces::i_udp_server::stop ( ) -> VoidResult
nodiscardpure virtual

Stops the UDP server.

Returns
VoidResult indicating success or failure.

Thread Safety

Thread-safe. Pending operations are cancelled.

Implemented in kcenon::network::core::messaging_udp_server, and kcenon::network::core::unified_udp_messaging_server< TlsPolicy >.


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