|
Network System 0.1.1
High-performance modular networking library for scalable client-server applications
|
Unified interface for all protocol client implementations. More...
#include <i_protocol_client.h>


Public Types | |
| using | receive_callback_t = std::function<void(const std::vector<uint8_t>&)> |
| Callback type for received data. | |
| using | connected_callback_t = std::function<void()> |
| Callback type for connection established. | |
| using | disconnected_callback_t = std::function<void()> |
| Callback type for disconnection. | |
| using | error_callback_t = std::function<void(std::error_code)> |
| Callback type for errors. | |
Public Member Functions | |
| virtual auto | start (std::string_view host, uint16_t port) -> VoidResult=0 |
| Starts the client and connects to the specified server. | |
| virtual auto | stop () -> VoidResult=0 |
| Stops the client and closes the connection. | |
| 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. | |
| virtual auto | set_observer (std::shared_ptr< connection_observer > observer) -> void=0 |
| Sets the connection observer for unified event handling. | |
| virtual auto | set_receive_callback (receive_callback_t callback) -> void=0 |
| Sets the callback for received data. | |
| virtual auto | set_connected_callback (connected_callback_t callback) -> void=0 |
| Sets the callback for connection established. | |
| virtual auto | set_disconnected_callback (disconnected_callback_t callback) -> void=0 |
| Sets the callback for disconnection. | |
| virtual auto | set_error_callback (error_callback_t callback) -> void=0 |
| Sets the callback for errors. | |
Public Member Functions inherited from kcenon::network::interfaces::i_network_component | |
| virtual | ~i_network_component ()=default |
| Virtual destructor for proper cleanup of derived classes. | |
| i_network_component (const i_network_component &)=delete | |
| i_network_component & | operator= (const i_network_component &)=delete |
| i_network_component (i_network_component &&)=delete | |
| i_network_component & | operator= (i_network_component &&)=delete |
Additional Inherited Members | |
Protected Member Functions inherited from kcenon::network::interfaces::i_network_component | |
| i_network_component ()=default | |
| Default constructor (only for derived classes) | |
| virtual auto | is_running () const -> bool=0 |
| Checks if the component is currently running. | |
| virtual auto | wait_for_stop () -> void=0 |
| Blocks until the component has stopped. | |
Unified interface for all protocol client implementations.
This interface establishes a common contract for all protocol clients (TCP, UDP, HTTP, WebSocket, QUIC, etc.) in the network system. It provides a consistent API for client lifecycle management, connection handling, and data transmission across different protocol implementations.
This interface was created to:
Implementations include:
Use set_observer() with a connection_observer implementation for unified event handling across all protocol types.
Individual callback setters are provided as an alternative to the observer pattern for simpler use cases.
Definition at line 99 of file i_protocol_client.h.
| using kcenon::network::interfaces::i_protocol_client::connected_callback_t = std::function<void()> |
Callback type for connection established.
Definition at line 105 of file i_protocol_client.h.
| using kcenon::network::interfaces::i_protocol_client::disconnected_callback_t = std::function<void()> |
Callback type for disconnection.
Definition at line 107 of file i_protocol_client.h.
| using kcenon::network::interfaces::i_protocol_client::error_callback_t = std::function<void(std::error_code)> |
Callback type for errors.
Definition at line 109 of file i_protocol_client.h.
| using kcenon::network::interfaces::i_protocol_client::receive_callback_t = std::function<void(const std::vector<uint8_t>&)> |
Callback type for received data.
Definition at line 103 of file i_protocol_client.h.
|
nodiscardpure virtual |
Checks if the client is connected to the server.
Thread-safe. Uses atomic operations for state checking.
Implemented in kcenon::network::core::messaging_client, kcenon::network::core::messaging_client, kcenon::network::internal::adapters::http_client_adapter, kcenon::network::internal::adapters::quic_client_adapter, kcenon::network::internal::adapters::udp_client_adapter, and kcenon::network::internal::adapters::ws_client_adapter.
|
nodiscardpure virtual |
Sends data to the connected server.
| data | The data to send. |
Thread-safe. Multiple sends may be queued concurrently. Send operations are serialized internally.
Implemented in kcenon::network::core::messaging_client, kcenon::network::internal::adapters::http_client_adapter, kcenon::network::internal::adapters::quic_client_adapter, kcenon::network::internal::adapters::udp_client_adapter, and kcenon::network::internal::adapters::ws_client_adapter.
|
pure virtual |
Sets the callback for connection established.
| callback | The callback function. |
Implemented in kcenon::network::core::messaging_client, kcenon::network::internal::adapters::http_client_adapter, kcenon::network::internal::adapters::quic_client_adapter, kcenon::network::internal::adapters::udp_client_adapter, and kcenon::network::internal::adapters::ws_client_adapter.
|
pure virtual |
Sets the callback for disconnection.
| callback | The callback function. |
Implemented in kcenon::network::core::messaging_client, kcenon::network::internal::adapters::http_client_adapter, kcenon::network::internal::adapters::quic_client_adapter, kcenon::network::internal::adapters::udp_client_adapter, and kcenon::network::internal::adapters::ws_client_adapter.
|
pure virtual |
Sets the callback for errors.
| callback | The callback function. |
Implemented in kcenon::network::core::messaging_client, kcenon::network::internal::adapters::http_client_adapter, kcenon::network::internal::adapters::quic_client_adapter, kcenon::network::internal::adapters::udp_client_adapter, and kcenon::network::internal::adapters::ws_client_adapter.
|
pure virtual |
Sets the connection observer for unified event handling.
| observer | The observer instance (shared ownership). |
The observer receives all connection events through a single interface:
This is the preferred method for event handling as it:
Thread-safe. Observer methods may be invoked from I/O threads. Observer must be thread-safe if shared across multiple clients.
Implemented in kcenon::network::core::messaging_client, kcenon::network::internal::adapters::http_client_adapter, kcenon::network::internal::adapters::quic_client_adapter, kcenon::network::internal::adapters::udp_client_adapter, and kcenon::network::internal::adapters::ws_client_adapter.
|
pure virtual |
Sets the callback for received data.
| callback | The callback function. |
Thread-safe. The callback may be invoked from I/O threads. Callback must be thread-safe if it accesses shared state.
Implemented in kcenon::network::core::messaging_client, kcenon::network::internal::adapters::http_client_adapter, kcenon::network::internal::adapters::quic_client_adapter, kcenon::network::internal::adapters::udp_client_adapter, and kcenon::network::internal::adapters::ws_client_adapter.
|
nodiscardpure virtual |
Starts the client and connects to the specified server.
| host | The server hostname or IP address. |
| port | The server port number. |
Thread-safe. Only one start operation can succeed at a time. Subsequent calls while running will return an error.
Implemented in kcenon::network::core::messaging_client, kcenon::network::internal::adapters::http_client_adapter, kcenon::network::internal::adapters::quic_client_adapter, kcenon::network::internal::adapters::udp_client_adapter, and kcenon::network::internal::adapters::ws_client_adapter.
|
nodiscardpure virtual |
Stops the client and closes the connection.
Thread-safe. Safe to call from any thread including callbacks. Pending operations will be cancelled and cleaned up.
Implemented in kcenon::network::core::messaging_client, kcenon::network::internal::adapters::http_client_adapter, kcenon::network::internal::adapters::quic_client_adapter, kcenon::network::internal::adapters::udp_client_adapter, and kcenon::network::internal::adapters::ws_client_adapter.