Networking

CWebSocket

A TLS WebSocket client for Catalyst values, with queued or delegated receiving.

C++23 mc/CWebSocket.h
#include <mc/CWebSocket.h>

The delegate is borrowed. Returning true from handle() consumes a message; false leaves it available to receive().

The client uses TLS with certificate verification. Keep callback state alive for the connection lifetime.

Jump to a declaration · 11

CWebSocketDelegate

Methods

handle

virtual bool handle(CWebSocket* s, cvar& msg);

Receives a decoded message on the connection’s callback thread. Return true to consume it or false to leave it for receive(); the default returns false. The message reference is borrowed for the callback.

CWebSocket

Methods

~CWebSocket

Stops the connection and joins its I/O work. Keep delegates and any state used by them alive until shutdown has finished.

setDelegate

void setDelegate(CWebSocketDelegate* delegate);

Installs a borrowed message delegate; nullptr selects the default. Replacement is synchronized with callbacks, and the delegate must remain alive while installed.

connect

bool connect(const cstr& host, const cstr& path, int port = 443);

Connects using TLS and performs the WebSocket handshake. host is a hostname and path begins with /; returns false for invalid input, an already active connection, or connection failure.

send

void send(const cvar& msg);

Serializes a supported JSON value and sends it as a text frame. Calls outside the socket’s callback thread wait for the local write; calls from that thread enqueue without blocking. The input value is retained.

receive

bool receive(cvar& msg);
bool receive(cvar& msg, double dt);

Retrieves a message not consumed by the delegate. Returns false for timeout or clean closure and rethrows asynchronous failures after queued messages drain; false leaves the output unchanged. Blocking receive is not allowed inside the socket’s own callback.