Skip to content

IWebSocketClient

IWebSocketClient defines a minimal interface for managing WebSocket connections, including lifecycle control and message handling via callbacks.

class IWebSocketClient : public ISubsystem {
public:
  virtual ~IWebSocketClient() = default;

  virtual void onOpen(MoveOnlyFunction<void()> cb) = 0;
  virtual void onMessage(MoveOnlyFunction<void(std::string_view)> cb) = 0;
  virtual void onClose(MoveOnlyFunction<void(int, std::string_view)> cb) = 0;

  virtual bool send(const std::string& data) = 0;
};

Purpose

  • Provide an abstraction for WebSocket communication used by exchange connectors and other components.
  • Enable pluggable transport implementations with consistent interface.

Responsibilities

Method Description
onOpen() Registers a callback to be invoked when the connection is successfully opened.
onMessage() Registers a callback for receiving incoming text messages.
onClose() Registers a callback to handle disconnection events with code and reason.
send() Sends a text message over the active WebSocket connection. Returns false if the frame was not handed to the transport (e.g. the socket is closed or not yet open); callers that need delivery confirmed must check it.
start() Initiates the WebSocket connection and starts event processing (inherited from ISubsystem)
stop() Gracefully closes the connection and stops background processing (inherited from ISubsystem)