Network System 0.1.1
High-performance modular networking library for scalable client-server applications
Loading...
Searching...
No Matches
websocket_facade.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
11#pragma once
12
21#include <chrono>
22#include <cstdint>
23#include <memory>
24#include <string>
25
27
29{
30 class i_protocol_client;
31 class i_protocol_server;
32} // namespace kcenon::network::interfaces
33
35{
36
77{
78public:
84 {
86 std::string client_id;
87
89 std::chrono::milliseconds ping_interval = std::chrono::seconds(30);
90 };
91
97 {
99 uint16_t port = 0;
100
102 std::string path = "/";
103
105 std::string server_id;
106 };
107
126 [[nodiscard]] auto create_client(const client_config& config) const
128
148 [[nodiscard]] auto create_server(const server_config& config) const
150
151private:
153 [[nodiscard]] static auto generate_client_id() -> std::string;
154
156 [[nodiscard]] static auto generate_server_id() -> std::string;
157
159 static auto validate_client_config(const client_config& config) -> VoidResult;
160
162 static auto validate_server_config(const server_config& config) -> VoidResult;
163};
164
165} // namespace kcenon::network::facade
Simplified facade for creating WebSocket clients and servers.
static auto generate_server_id() -> std::string
Generates a unique server ID.
static auto validate_client_config(const client_config &config) -> VoidResult
Validates client configuration.
static auto validate_server_config(const server_config &config) -> VoidResult
Validates server configuration.
static auto generate_client_id() -> std::string
Generates a unique client ID.
auto create_server(const server_config &config) const -> Result< std::shared_ptr< interfaces::i_protocol_server > >
Creates a WebSocket server with the specified configuration.
auto create_client(const client_config &config) const -> Result< std::shared_ptr< interfaces::i_protocol_client > >
Creates a WebSocket client with the specified configuration.
Result< std::monostate > VoidResult
Public header for Result<T> error handling types.
Configuration for creating a WebSocket client.
std::string client_id
Client identifier (auto-generated if not provided)
std::chrono::milliseconds ping_interval
Ping interval (default: 30 seconds)
Configuration for creating a WebSocket server.
std::string server_id
Server identifier (auto-generated if not provided)
std::string path
WebSocket path (default: "/")