Network System 0.1.1
High-performance modular networking library for scalable client-server applications
Loading...
Searching...
No Matches
i_udp_client.h
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2024, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
5#pragma once
6
8
9#include <cstdint>
10#include <functional>
11#include <string_view>
12#include <system_error>
13#include <vector>
14
16
18{
19
44 {
45 public:
48 {
49 std::string address;
50 uint16_t port;
51 };
52
54 using receive_callback_t = std::function<void(
55 const std::vector<uint8_t>&,
56 const endpoint_info&)>;
57
59 using error_callback_t = std::function<void(std::error_code)>;
60
62 using send_callback_t = std::function<void(std::error_code, std::size_t)>;
63
83 [[nodiscard]] virtual auto start(std::string_view host, uint16_t port) -> VoidResult = 0;
84
92 [[nodiscard]] virtual auto stop() -> VoidResult = 0;
93
107 [[nodiscard]] virtual auto send(
108 std::vector<uint8_t>&& data,
109 send_callback_t handler = nullptr) -> VoidResult = 0;
110
123 [[nodiscard]] virtual auto set_target(std::string_view host, uint16_t port) -> VoidResult = 0;
124
133 virtual auto set_receive_callback(receive_callback_t callback) -> void = 0;
134
139 virtual auto set_error_callback(error_callback_t callback) -> void = 0;
140 };
141
142} // namespace kcenon::network::interfaces
Base interface for all network components.
Interface for UDP client components.
std::function< void(std::error_code, std::size_t)> send_callback_t
Callback type for send completion.
virtual auto set_error_callback(error_callback_t callback) -> void=0
Sets the callback for errors.
std::function< void( const std::vector< uint8_t > &, const endpoint_info &)> receive_callback_t
Callback type for received data (includes sender endpoint)
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 start(std::string_view host, uint16_t port) -> VoidResult=0
Starts the UDP client targeting the specified endpoint.
virtual auto set_target(std::string_view host, uint16_t port) -> VoidResult=0
Changes the target endpoint for future sends.
std::function< void(std::error_code)> error_callback_t
Callback type for errors.
virtual auto set_receive_callback(receive_callback_t callback) -> void=0
Sets the callback for received datagrams.
virtual auto stop() -> VoidResult=0
Stops the UDP client.
Base interface for all network components.
Network-specific error and result type definitions.
Endpoint information for UDP datagrams.