Network System 0.1.1
High-performance modular networking library for scalable client-server applications
Loading...
Searching...
No Matches
i_protocol_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
12#pragma once
13
22#include "i_network_component.h"
23#include "connection_observer.h"
24
25#include <cstdint>
26#include <functional>
27#include <memory>
28#include <string_view>
29#include <system_error>
30#include <vector>
31
33
35{
36
100 {
101 public:
103 using receive_callback_t = std::function<void(const std::vector<uint8_t>&)>;
105 using connected_callback_t = std::function<void()>;
107 using disconnected_callback_t = std::function<void()>;
109 using error_callback_t = std::function<void(std::error_code)>;
110
139 [[nodiscard]] virtual auto start(std::string_view host, uint16_t port) -> VoidResult = 0;
140
164 [[nodiscard]] virtual auto stop() -> VoidResult = 0;
165
191 [[nodiscard]] virtual auto send(std::vector<uint8_t>&& data) -> VoidResult = 0;
192
212 [[nodiscard]] virtual auto is_connected() const -> bool = 0;
213
251 virtual auto set_observer(std::shared_ptr<connection_observer> observer) -> void = 0;
252
261 virtual auto set_receive_callback(receive_callback_t callback) -> void = 0;
262
267 virtual auto set_connected_callback(connected_callback_t callback) -> void = 0;
268
273 virtual auto set_disconnected_callback(disconnected_callback_t callback) -> void = 0;
274
279 virtual auto set_error_callback(error_callback_t callback) -> void = 0;
280 };
281
282} // namespace kcenon::network::interfaces
Observer interface for client connection events.
Base interface for all network components.
Unified interface for all protocol client implementations.
virtual auto stop() -> VoidResult=0
Stops the client and closes the connection.
std::function< void(const std::vector< uint8_t > &)> receive_callback_t
Callback type for received data.
std::function< void()> connected_callback_t
Callback type for connection established.
virtual auto set_error_callback(error_callback_t callback) -> void=0
Sets the callback for errors.
std::function< void(std::error_code)> error_callback_t
Callback type for errors.
virtual auto start(std::string_view host, uint16_t port) -> VoidResult=0
Starts the client and connects to the specified server.
virtual auto set_connected_callback(connected_callback_t callback) -> void=0
Sets the callback for connection established.
virtual auto set_receive_callback(receive_callback_t callback) -> void=0
Sets the callback for received data.
virtual auto set_disconnected_callback(disconnected_callback_t callback) -> void=0
Sets the callback for disconnection.
virtual auto set_observer(std::shared_ptr< connection_observer > observer) -> void=0
Sets the connection observer for unified event handling.
virtual auto send(std::vector< uint8_t > &&data) -> VoidResult=0
Sends data to the connected server.
virtual auto is_connected() const -> bool=0
Checks if the client is connected to the server.
std::function< void()> disconnected_callback_t
Callback type for disconnection.
Observer interface for connection state change notifications.
Base interface for all network components.
Public header for Result<T> error handling types.