Network System 0.1.1
High-performance modular networking library for scalable client-server applications
Loading...
Searching...
No Matches
i_udp_server.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#include "i_udp_client.h"
9
10#include <cstdint>
11#include <functional>
12#include <system_error>
13#include <vector>
14
16
18{
19
40 {
41 public:
44
46 using receive_callback_t = std::function<void(
47 const std::vector<uint8_t>&,
48 const endpoint_info&)>;
49
51 using error_callback_t = std::function<void(std::error_code)>;
52
54 using send_callback_t = std::function<void(std::error_code, std::size_t)>;
55
73 [[nodiscard]] virtual auto start(uint16_t port) -> VoidResult = 0;
74
82 [[nodiscard]] virtual auto stop() -> VoidResult = 0;
83
94 [[nodiscard]] virtual auto send_to(
95 const endpoint_info& endpoint,
96 std::vector<uint8_t>&& data,
97 send_callback_t handler = nullptr) -> VoidResult = 0;
98
107 virtual auto set_receive_callback(receive_callback_t callback) -> void = 0;
108
113 virtual auto set_error_callback(error_callback_t callback) -> void = 0;
114 };
115
116} // namespace kcenon::network::interfaces
Base interface for all network components.
Interface for UDP server components.
virtual auto stop() -> VoidResult=0
Stops the UDP server.
std::function< void( const std::vector< uint8_t > &, const endpoint_info &)> receive_callback_t
Callback type for received data (includes sender endpoint)
virtual auto set_receive_callback(receive_callback_t callback) -> void=0
Sets the callback for received datagrams.
virtual auto start(uint16_t port) -> VoidResult=0
Starts the UDP server on the specified port.
std::function< void(std::error_code, std::size_t)> send_callback_t
Callback type for send completion.
std::function< void(std::error_code)> error_callback_t
Callback type for errors.
virtual auto set_error_callback(error_callback_t callback) -> void=0
Sets the callback for errors.
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.
Base interface for all network components.
Network-specific error and result type definitions.
Endpoint information for UDP datagrams.