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

Interface for UDP client components. More...

#include <i_udp_client.h>

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

Classes

struct  endpoint_info
 Endpoint information for UDP datagrams. More...
 

Public Types

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 (std::string_view host, uint16_t port) -> VoidResult=0
 Starts the UDP client targeting the specified endpoint.
 
virtual auto stop () -> VoidResult=0
 Stops the UDP client.
 
virtual auto send (std::vector< uint8_t > &&data, send_callback_t handler=nullptr) -> VoidResult=0
 Sends a datagram to the configured target endpoint.
 
virtual auto set_target (std::string_view host, uint16_t port) -> VoidResult=0
 Changes the target endpoint for future sends.
 
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 client components.

This interface extends i_network_component with UDP-specific operations such as connectionless datagram transmission and receiving datagrams with sender endpoint information.

Key Characteristics

  • Connectionless: Each send operation is independent
  • Unreliable: No built-in acknowledgment or ordering
  • Endpoint-aware: Receive callbacks include sender information

Callback Types

  • receive_callback_t: Called when data is received (includes sender endpoint)
  • error_callback_t: Called when an error occurs

Thread Safety

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

Definition at line 43 of file i_udp_client.h.

Member Typedef Documentation

◆ error_callback_t

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

Callback type for errors.

Definition at line 59 of file i_udp_client.h.

◆ receive_callback_t

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

Callback type for received data (includes sender endpoint)

Definition at line 54 of file i_udp_client.h.

◆ send_callback_t

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

Callback type for send completion.

Definition at line 62 of file i_udp_client.h.

Member Function Documentation

◆ send()

virtual auto kcenon::network::interfaces::i_udp_client::send ( std::vector< uint8_t > && data,
send_callback_t handler = nullptr ) -> VoidResult
nodiscardpure virtual

Sends a datagram to the configured target endpoint.

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

Error Conditions

  • Returns error if not running
  • Returns error if send fails

Thread Safety

Thread-safe. Multiple sends may be queued.

Implemented in kcenon::network::core::messaging_udp_client, and kcenon::network::core::unified_udp_messaging_client< TlsPolicy >.

◆ set_error_callback()

virtual auto kcenon::network::interfaces::i_udp_client::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_client, and kcenon::network::core::unified_udp_messaging_client< TlsPolicy >.

◆ set_receive_callback()

virtual auto kcenon::network::interfaces::i_udp_client::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 to the correct peer.

Implemented in kcenon::network::core::messaging_udp_client, and kcenon::network::core::unified_udp_messaging_client< TlsPolicy >.

◆ set_target()

virtual auto kcenon::network::interfaces::i_udp_client::set_target ( std::string_view host,
uint16_t port ) -> VoidResult
nodiscardpure virtual

Changes the target endpoint for future sends.

Parameters
hostThe new target hostname or IP address.
portThe new target port number.
Returns
VoidResult indicating success or failure.

Error Conditions

  • Returns error if name resolution fails

Thread Safety

Thread-safe.

Implemented in kcenon::network::core::messaging_udp_client, and kcenon::network::core::unified_udp_messaging_client< TlsPolicy >.

◆ start()

virtual auto kcenon::network::interfaces::i_udp_client::start ( std::string_view host,
uint16_t port ) -> VoidResult
nodiscardpure virtual

Starts the UDP client targeting the specified endpoint.

Parameters
hostThe target hostname or IP address.
portThe target port number.
Returns
VoidResult indicating success or failure.

Behavior

  • Creates a UDP socket
  • Resolves the target endpoint
  • Begins listening for incoming datagrams

Error Conditions

  • Returns error if already running
  • Returns error if socket creation fails
  • Returns error if name resolution fails

Thread Safety

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

Implemented in kcenon::network::core::messaging_udp_client, and kcenon::network::core::unified_udp_messaging_client< TlsPolicy >.

◆ stop()

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

Stops the UDP client.

Returns
VoidResult indicating success or failure.

Thread Safety

Thread-safe. Pending operations are cancelled.

Implemented in kcenon::network::core::messaging_udp_client, and kcenon::network::core::unified_udp_messaging_client< TlsPolicy >.


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