Network System 0.1.1
High-performance modular networking library for scalable client-server applications
Loading...
Searching...
No Matches
i_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
12#include "i_network_component.h"
13#include "connection_observer.h"
14
15#include <cstdint>
16#include <functional>
17#include <memory>
18#include <string_view>
19#include <system_error>
20#include <vector>
21
23
25{
26
52 {
53 public:
55 using receive_callback_t = std::function<void(const std::vector<uint8_t>&)>;
57 using connected_callback_t = std::function<void()>;
59 using disconnected_callback_t = std::function<void()>;
61 using error_callback_t = std::function<void(std::error_code)>;
62
77 [[nodiscard]] virtual auto start(std::string_view host, uint16_t port) -> VoidResult = 0;
78
90 [[nodiscard]] virtual auto stop() -> VoidResult = 0;
91
104 [[nodiscard]] virtual auto send(std::vector<uint8_t>&& data) -> VoidResult = 0;
105
114 [[nodiscard]] virtual auto is_connected() const -> bool = 0;
115
135 virtual auto set_observer(std::shared_ptr<connection_observer> observer) -> void = 0;
136
144 virtual auto set_receive_callback(receive_callback_t callback) -> void = 0;
145
150 virtual auto set_connected_callback(connected_callback_t callback) -> void = 0;
151
156 virtual auto set_disconnected_callback(disconnected_callback_t callback) -> void = 0;
157
162 virtual auto set_error_callback(error_callback_t callback) -> void = 0;
163 };
164
165} // namespace kcenon::network::interfaces
Observer interface for client connection events.
Base interface for client-side network components.
Definition i_client.h:52
std::function< void()> connected_callback_t
Callback type for connection established.
Definition i_client.h:57
virtual auto send(std::vector< uint8_t > &&data) -> VoidResult=0
Sends data to the connected server.
virtual auto set_error_callback(error_callback_t callback) -> void=0
Sets the callback for errors.
virtual auto set_disconnected_callback(disconnected_callback_t callback) -> void=0
Sets the callback for disconnection.
virtual auto is_connected() const -> bool=0
Checks if the client is connected to the server.
virtual auto stop() -> VoidResult=0
Stops the client and closes the connection.
virtual auto set_connected_callback(connected_callback_t callback) -> void=0
Sets the callback for connection established.
std::function< void(std::error_code)> error_callback_t
Callback type for errors.
Definition i_client.h:61
virtual auto start(std::string_view host, uint16_t port) -> VoidResult=0
Starts the client and connects to the specified server.
virtual auto set_receive_callback(receive_callback_t callback) -> void=0
Sets the callback for received data.
std::function< void()> disconnected_callback_t
Callback type for disconnection.
Definition i_client.h:59
std::function< void(const std::vector< uint8_t > &)> receive_callback_t
Callback type for received data.
Definition i_client.h:55
virtual auto set_observer(std::shared_ptr< connection_observer > observer) -> void=0
Sets the connection observer for unified event handling.
Base interface for all network components.
Observer interface for connection state change notifications.
Base interface for all network components.
Public header for Result<T> error handling types.