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

Interface for WebSocket client components. More...

#include <i_websocket_client.h>

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

Public Types

using text_callback_t = std::function<void(const std::string&)>
 Callback type for text messages.
 
using binary_callback_t = std::function<void(const std::vector<uint8_t>&)>
 Callback type for binary messages.
 
using connected_callback_t = std::function<void()>
 Callback type for connection established.
 
using disconnected_callback_t = std::function<void(uint16_t code, std::string_view reason)>
 Callback type for disconnection (with close code and reason)
 
using error_callback_t = std::function<void(std::error_code)>
 Callback type for errors.
 
using send_callback_t = std::function<void(std::error_code, std::size_t)>
 Callback type for send completion.
 

Public Member Functions

virtual auto start (std::string_view host, uint16_t port, std::string_view path="/") -> VoidResult=0
 Starts the WebSocket client connecting to the specified endpoint.
 
virtual auto stop () -> VoidResult=0
 Stops the WebSocket client.
 
virtual auto is_connected () const -> bool=0
 Checks if the WebSocket connection is established.
 
virtual auto send_text (std::string &&message, send_callback_t handler=nullptr) -> VoidResult=0
 Sends a text message.
 
virtual auto send_binary (std::vector< uint8_t > &&data, send_callback_t handler=nullptr) -> VoidResult=0
 Sends a binary message.
 
virtual auto ping (std::vector< uint8_t > &&payload={}) -> VoidResult=0
 Sends a ping frame.
 
virtual auto close (uint16_t code=1000, std::string_view reason="") -> VoidResult=0
 Closes the WebSocket connection gracefully.
 
virtual auto set_text_callback (text_callback_t callback) -> void=0
 Sets the callback for text messages.
 
virtual auto set_binary_callback (binary_callback_t callback) -> void=0
 Sets the callback for binary messages.
 
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

Interface for WebSocket client components.

This interface extends i_network_component with WebSocket-specific operations such as text/binary message sending, path-based connections, and close frame handling.

Key Features

  • Text and binary message support
  • Path-based connection (e.g., "/ws", "/api/stream")
  • Ping/pong keepalive support
  • Graceful close with status codes

Thread Safety

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

Definition at line 41 of file i_websocket_client.h.

Member Typedef Documentation

◆ binary_callback_t

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

Callback type for binary messages.

Definition at line 48 of file i_websocket_client.h.

◆ connected_callback_t

Callback type for connection established.

Definition at line 51 of file i_websocket_client.h.

◆ disconnected_callback_t

using kcenon::network::interfaces::i_websocket_client::disconnected_callback_t = std::function<void(uint16_t code, std::string_view reason)>

Callback type for disconnection (with close code and reason)

Definition at line 54 of file i_websocket_client.h.

◆ error_callback_t

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

Callback type for errors.

Definition at line 57 of file i_websocket_client.h.

◆ send_callback_t

using kcenon::network::interfaces::i_websocket_client::send_callback_t = std::function<void(std::error_code, std::size_t)>

Callback type for send completion.

Definition at line 60 of file i_websocket_client.h.

◆ text_callback_t

using kcenon::network::interfaces::i_websocket_client::text_callback_t = std::function<void(const std::string&)>

Callback type for text messages.

Definition at line 45 of file i_websocket_client.h.

Member Function Documentation

◆ close()

virtual auto kcenon::network::interfaces::i_websocket_client::close ( uint16_t code = 1000,
std::string_view reason = "" ) -> VoidResult
nodiscardpure virtual

Closes the WebSocket connection gracefully.

Parameters
codeThe close status code.
reasonOptional human-readable reason.
Returns
VoidResult indicating success or failure.

Implemented in kcenon::network::core::messaging_ws_client.

◆ is_connected()

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

Checks if the WebSocket connection is established.

Returns
true if connected, false otherwise.

Implemented in kcenon::network::core::messaging_ws_client.

◆ ping()

virtual auto kcenon::network::interfaces::i_websocket_client::ping ( std::vector< uint8_t > && payload = {}) -> VoidResult
nodiscardpure virtual

Sends a ping frame.

Parameters
payloadOptional payload data (max 125 bytes).
Returns
VoidResult indicating success or failure.

Implemented in kcenon::network::core::messaging_ws_client.

◆ send_binary()

virtual auto kcenon::network::interfaces::i_websocket_client::send_binary ( std::vector< uint8_t > && data,
send_callback_t handler = nullptr ) -> VoidResult
nodiscardpure virtual

Sends a binary message.

Parameters
dataThe binary data to send.
handlerOptional completion handler.
Returns
VoidResult indicating success or failure.

Error Conditions

  • Returns error if not connected

Implemented in kcenon::network::core::messaging_ws_client.

◆ send_text()

virtual auto kcenon::network::interfaces::i_websocket_client::send_text ( std::string && message,
send_callback_t handler = nullptr ) -> VoidResult
nodiscardpure virtual

Sends a text message.

Parameters
messageThe text message to send.
handlerOptional completion handler.
Returns
VoidResult indicating success or failure.

Error Conditions

  • Returns error if not connected

Implemented in kcenon::network::core::messaging_ws_client.

◆ set_binary_callback()

virtual auto kcenon::network::interfaces::i_websocket_client::set_binary_callback ( binary_callback_t callback) -> void
pure virtual

Sets the callback for binary messages.

Parameters
callbackThe callback function.

Implemented in kcenon::network::core::messaging_ws_client.

◆ set_connected_callback()

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

Sets the callback for connection established.

Parameters
callbackThe callback function.

Implemented in kcenon::network::core::messaging_ws_client.

◆ set_disconnected_callback()

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

Sets the callback for disconnection.

Parameters
callbackThe callback function.

Implemented in kcenon::network::core::messaging_ws_client.

◆ set_error_callback()

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

Sets the callback for errors.

Parameters
callbackThe callback function.

Implemented in kcenon::network::core::messaging_ws_client.

◆ set_text_callback()

virtual auto kcenon::network::interfaces::i_websocket_client::set_text_callback ( text_callback_t callback) -> void
pure virtual

Sets the callback for text messages.

Parameters
callbackThe callback function.

Implemented in kcenon::network::core::messaging_ws_client.

◆ start()

virtual auto kcenon::network::interfaces::i_websocket_client::start ( std::string_view host,
uint16_t port,
std::string_view path = "/" ) -> VoidResult
nodiscardpure virtual

Starts the WebSocket client connecting to the specified endpoint.

Parameters
hostThe server hostname or IP address.
portThe server port number.
pathThe WebSocket path (default: "/").
Returns
VoidResult indicating success or failure.

Behavior

  • Establishes TCP connection
  • Performs WebSocket handshake
  • Begins message receive loop

Error Conditions

  • Returns error if already running
  • Returns error if connection fails
  • Returns error if handshake fails

Thread Safety

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

Implemented in kcenon::network::core::messaging_ws_client.

◆ stop()

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

Stops the WebSocket client.

Returns
VoidResult indicating success or failure.

Behavior

Performs graceful close if connected.

Thread Safety

Thread-safe.

Implemented in kcenon::network::core::messaging_ws_client.


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