121 bool wait_for_stop(std::chrono::milliseconds timeout = std::chrono::milliseconds(5000));
197 void set_heartbeat(
bool enable, std::chrono::seconds interval = std::chrono::seconds(30));
253 const std::string& session_id,
254 std::span<const uint8_t> data)>;
279 bool start_server(uint16_t port,
int backlog = 128);
288 bool start_server(std::string_view address, uint16_t port,
int backlog = 128);
300 bool wait_for_stop(std::chrono::milliseconds timeout = std::chrono::milliseconds(5000));
308 bool send_to(std::string_view session_id, std::span<const uint8_t> data);
316 bool send_to(std::string_view session_id, std::string_view data);
322 void broadcast(std::span<const uint8_t> data);
328 void broadcast(std::string_view data);
334 void disconnect(std::string_view session_id);
346 size_t client_count() const noexcept;
352 std::string_view server_id() const noexcept;
411 const std::
string& session_id() const noexcept;
417 bool is_active() const noexcept;
423 std::
string remote_address() const;
429 uint16_t remote_port() const;
436 bool send(std::span<const uint8_t> data);
A basic TCP client that connects to a remote host, sends/receives data using asynchronous operations,...
auto client_id() const -> const std::string &
Returns the client identifier.
virtual ~messaging_client() noexcept
Destructor - automatically stops the client if running.
auto wait_for_stop() -> void override
Waits for the client to stop.
void set_disconnection_callback(disconnection_callback callback)
Set disconnection callback.
auto is_connected() const -> bool override
Checks if the client is connected to the server (IProtocolClient interface).
auto start_client(std::string_view host, unsigned short port) -> VoidResult
Starts the client and connects to the specified host and port.
auto stop_client() -> VoidResult
Stops the client and disconnects from the server.
auto set_error_callback(error_callback_t callback) -> void override
Sets the callback for errors.
auto send_packet(std::vector< uint8_t > &&data) -> VoidResult
Sends data to the connected server.
auto send(std::vector< uint8_t > &&data) -> VoidResult override
Sends data to the connected server (IProtocolClient interface).
void set_data_callback(data_callback callback)
Set data received callback.
void set_connection_callback(connection_callback callback)
Set connection callback.
connection_state get_state() const noexcept
Get the current connection state.
messaging_client(std::string_view client_id)
Construct a client with a given client_id.
std::unique_ptr< impl > pimpl_
auto is_running() const -> bool override
Checks if the client is currently running.
void set_heartbeat(bool enable, std::chrono::seconds interval=std::chrono::seconds(30))
Enable heartbeat mechanism.
void set_auto_reconnect(bool enable, std::chrono::seconds delay=std::chrono::seconds(5))
Enable automatic reconnection.
A server class that manages incoming TCP connections, creating messaging_session instances for each a...
messaging_server(std::string_view server_id)
Construct a server with a given server_id.
std::function< void(const std::string &session_id)> client_disconnected_callback
Callback type for client disconnection events.
virtual ~messaging_server() noexcept
Destructor - automatically stops the server if running.
std::function< void(const std::string &session_id)> client_connected_callback
Callback type for client connection events.
std::function< void( const std::string &session_id, std::span< const uint8_t > data)> client_data_callback
Callback type for client data events.
Represents a client session on the server.
messaging_session(std::string session_id)
Construct a session with a unique ID.
virtual ~messaging_session() noexcept
Destructor.
std::function< void()> disconnection_callback
std::function< void()> connection_callback
Callback type aliases for messaging.
std::function< void(const std::string &)> error_callback
connection_state
Connection state enumeration.
std::function< void(std::span< const uint8_t >)> data_callback