45 :
host(std::move(host_)),
port(port_) {}
52 return host +
":" + std::to_string(
port);
60 return !(*
this == other);
150 virtual ::kcenon::common::VoidResult
connect(
const std::string& host, uint16_t port) = 0;
169 virtual ::kcenon::common::VoidResult
send(std::span<const uint8_t> data) = 0;
178 virtual ::kcenon::common::VoidResult
send(std::span<const uint8_t> data,
194 virtual ::kcenon::common::VoidResult
send_to(std::span<const uint8_t> data,
248 return send(std::span<const uint8_t>(
249 reinterpret_cast<const uint8_t*
>(data.data()),
260 return send_to(std::span<const uint8_t>(
261 reinterpret_cast<const uint8_t*
>(data.data()),
262 data.size()), endpoint);
278 "UDP client not available",
285 "UDP client not available",
293 "UDP client not available",
304 return "null_udp_client";
Result type for error handling with member function support.
Interface for modules that provide UDP client implementations.
virtual ~IUdpClientProvider()=default
virtual std::shared_ptr< IUdpClient > create_udp_client()=0
Create a new UDP client.
virtual std::shared_ptr< IUdpClient > get_udp_client()=0
Get the default UDP client instance.
Abstract interface for UDP client implementations.
virtual udp_statistics get_statistics() const
Get send statistics.
::kcenon::common::VoidResult send(const std::string &data)
Send string data to the connected endpoint.
virtual bool is_connected() const =0
Check if the client is connected to an endpoint.
virtual void reset_statistics()
Reset statistics.
virtual::kcenon::common::VoidResult send_to(std::span< const uint8_t > data, const udp_endpoint &endpoint)=0
Send data to a specific endpoint (connectionless)
virtual std::string get_implementation_name() const
Get the implementation name for logging/debugging.
::kcenon::common::VoidResult send_to(const std::string &data, const udp_endpoint &endpoint)
Send string data to a specific endpoint.
virtual::kcenon::common::VoidResult send(std::span< const uint8_t > data)=0
Send data to the connected endpoint.
virtual::kcenon::common::VoidResult connect(const udp_endpoint &endpoint)
Connect to a remote endpoint.
virtual::kcenon::common::VoidResult send(std::span< const uint8_t > data, const udp_send_options &options)
Send data to the connected endpoint with options.
virtual ~IUdpClient()=default
virtual::kcenon::common::VoidResult connect(const std::string &host, uint16_t port)=0
Connect to a remote endpoint for optimized sending.
virtual std::optional< udp_endpoint > get_remote_endpoint() const
Get the currently connected endpoint.
virtual void disconnect()=0
Disconnect from the current endpoint.
Null implementation for when UDP transport is disabled.
::kcenon::common::VoidResult connect(const std::string &, uint16_t) override
Connect to a remote endpoint for optimized sending.
::kcenon::common::VoidResult send(std::span< const uint8_t >) override
Send data to the connected endpoint.
::kcenon::common::VoidResult send_to(std::span< const uint8_t >, const udp_endpoint &) override
Send data to a specific endpoint (connectionless)
std::string get_implementation_name() const override
Get the implementation name for logging/debugging.
bool is_connected() const override
Check if the client is connected to an endpoint.
void disconnect() override
Disconnect from the current endpoint.
constexpr int NOT_INITIALIZED
std::function< std::shared_ptr< IUdpClient >()> UdpClientFactory
Factory function type for creating UDP client instances.
Umbrella header for Result<T> type and related utilities.
Standard error information used by Result<T>.
Represents a UDP endpoint (host and port)
bool operator!=(const udp_endpoint &other) const
uint16_t port
Port number.
std::string to_string() const
Convert to string representation.
std::string host
Hostname or IP address.
udp_endpoint(std::string host_, uint16_t port_)
bool operator==(const udp_endpoint &other) const
Options for UDP send operations.
udp_send_options()=default
uint8_t ttl
TTL (Time To Live) value, 0 means use system default.
std::chrono::milliseconds timeout
Send timeout (0 means no timeout / non-blocking)
bool dont_fragment
Whether to set the don't-fragment flag (if supported)
Statistics for UDP client operations.
uint64_t send_failures
Number of failed send operations.
uint64_t packets_sent
Total number of packets sent.
uint64_t bytes_sent
Total number of bytes sent.
std::optional< std::chrono::steady_clock::time_point > last_send_time
Timestamp of last successful send.
void reset()
Reset all statistics.