Network System 0.1.1
High-performance modular networking library for scalable client-server applications
Loading...
Searching...
No Matches
kcenon::network::interfaces::i_client Interface Referenceabstract

Base interface for client-side network components. More...

#include <i_client.h>

Inheritance diagram for kcenon::network::interfaces::i_client:
Inheritance graph
Collaboration diagram for kcenon::network::interfaces::i_client:
Collaboration graph

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_componentoperator= (const i_network_component &)=delete
 
 i_network_component (i_network_component &&)=delete
 
i_network_componentoperator= (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.
 

Detailed Description

Base interface for client-side network components.

This interface extends i_network_component with client-specific operations such as connecting to a server, sending data, and handling connection state.

Observer Pattern (Recommended)

Use set_observer() with a connection_observer implementation for unified event handling. See connection_observer.h for details.

Callback Types

  • receive_callback_t: Called when data is received
  • connected_callback_t: Called when connection is established
  • disconnected_callback_t: Called when connection is lost
  • error_callback_t: Called when an error occurs

Thread Safety

  • All public methods must be thread-safe
  • Callbacks may be invoked from I/O threads
See also
connection_observer

Definition at line 51 of file i_client.h.

Member Typedef Documentation

◆ connected_callback_t

Callback type for connection established.

Definition at line 57 of file i_client.h.

◆ disconnected_callback_t

Callback type for disconnection.

Definition at line 59 of file i_client.h.

◆ error_callback_t

using kcenon::network::interfaces::i_client::error_callback_t = std::function<void(std::error_code)>

Callback type for errors.

Definition at line 61 of file i_client.h.

◆ receive_callback_t

using kcenon::network::interfaces::i_client::receive_callback_t = std::function<void(const std::vector<uint8_t>&)>

Callback type for received data.

Definition at line 55 of file i_client.h.

Member Function Documentation

◆ is_connected()

virtual auto kcenon::network::interfaces::i_client::is_connected ( ) const -> bool
nodiscardpure virtual

Checks if the client is connected to the server.

Returns
true if connected, false otherwise.

Note

A client can be running but not connected (e.g., during connection establishment or after disconnection).

◆ send()

virtual auto kcenon::network::interfaces::i_client::send ( std::vector< uint8_t > && data) -> VoidResult
nodiscardpure virtual

Sends data to the connected server.

Parameters
dataThe data to send.
Returns
VoidResult indicating success or failure.

Error Conditions

  • Returns error if not connected
  • Returns error if send operation fails

Thread Safety

Thread-safe. Multiple sends may be queued.

◆ set_connected_callback()

virtual auto kcenon::network::interfaces::i_client::set_connected_callback ( connected_callback_t callback) -> void
pure virtual

Sets the callback for connection established.

Parameters
callbackThe callback function.

◆ set_disconnected_callback()

virtual auto kcenon::network::interfaces::i_client::set_disconnected_callback ( disconnected_callback_t callback) -> void
pure virtual

Sets the callback for disconnection.

Parameters
callbackThe callback function.

◆ set_error_callback()

virtual auto kcenon::network::interfaces::i_client::set_error_callback ( error_callback_t callback) -> void
pure virtual

Sets the callback for errors.

Parameters
callbackThe callback function.

◆ set_observer()

virtual auto kcenon::network::interfaces::i_client::set_observer ( std::shared_ptr< connection_observer > observer) -> void
pure virtual

Sets the connection observer for unified event handling.

Parameters
observerThe observer instance (shared ownership).

The observer receives all connection events through a single interface, replacing the need for individual callback setters.

Usage

auto observer = std::make_shared<my_observer>();
client->set_observer(observer);

Thread Safety

Thread-safe. Observer methods may be invoked from I/O threads.

See also
connection_observer
callback_adapter

◆ set_receive_callback()

virtual auto kcenon::network::interfaces::i_client::set_receive_callback ( receive_callback_t callback) -> void
pure virtual

Sets the callback for received data.

Parameters
callbackThe callback function.

Thread Safety

Thread-safe. The callback may be invoked from I/O threads.

◆ start()

virtual auto kcenon::network::interfaces::i_client::start ( std::string_view host,
uint16_t port ) -> VoidResult
nodiscardpure virtual

Starts the client and connects to the specified server.

Parameters
hostThe server hostname or IP address.
portThe server port number.
Returns
VoidResult indicating success or failure.

Error Conditions

  • Returns error if already running
  • Returns error if connection fails
  • Returns error if host resolution fails

Thread Safety

Thread-safe. Only one start operation can succeed at a time.

◆ stop()

virtual auto kcenon::network::interfaces::i_client::stop ( ) -> VoidResult
nodiscardpure virtual

Stops the client and closes the connection.

Returns
VoidResult indicating success or failure.

Error Conditions

  • Returns error if not running

Thread Safety

Thread-safe. Cancels pending operations and triggers disconnected callback.


The documentation for this interface was generated from the following file: