Skip to content

Claude/add websocket support cg s6q#27

Merged
bobjansen merged 2 commits intomainfrom
claude/add-websocket-support-cgS6q
Mar 7, 2026
Merged

Claude/add websocket support cg s6q#27
bobjansen merged 2 commits intomainfrom
claude/add-websocket-support-cgS6q

Conversation

@bobjansen
Copy link
Owner

No description provided.

claude added 2 commits March 7, 2026 12:28
Implements a new `websocket` plugin (libs/websocket/) that mirrors the
existing UDP plugin but uses the WebSocket protocol over TCP.  This lets
Ibex stream computed results (e.g. OHLC bars) to browser-based dashboards
without any extra proxy layer.

Plugin functions:
  ws_recv(port: Int) -> DataFrame
    WebSocket server source.  Accepts connections on `port` and returns
    one JSON tick row per call.  Uses a 200 ms select() timeout so that
    the stream event loop can fire wall-clock time-bucket flushes while
    idle, returning StreamTimeout between messages.

  ws_send(df: DataFrame, port: Int) -> Int
    WebSocket server sink.  Broadcasts each DataFrame row as a JSON text
    frame to all connected clients on `port`.  Creates the TCP listener
    lazily, so ws_send works standalone without a paired ws_recv.

Implementation highlights:
  - Zero third-party dependencies: SHA-1 and Base64 are implemented
    inline (header-only, RFC 3174) for the WebSocket opening handshake.
  - Full WebSocket framing: encodes server→client frames (unmasked) and
    decodes client→server frames (masked), including close and ping/pong
    control frames.
  - Shared server state per port via a static map so ws_recv and ws_send
    cooperate on the same listener socket and client list.
  - Non-blocking accept() on the listen socket ensures ws_send never
    stalls waiting for new connections.

Also adds three example files under examples/market_stream/:
  - market_stream_ws.ibex  — UDP ticks → resample → WebSocket OHLC sink
  - ws_client.py           — stdlib-only Python WebSocket client
  - ws_dashboard.html      — browser dashboard with auto-reconnect

https://claude.ai/code/session_014KkcPe2ttDpPoJBPTn7ijP
Three additions to docs/index.html:

- Hero lead: mention WebSocket servers for browser dashboards alongside
  the existing stream pipeline description.
- Feature card: new "WebSocket streaming" card explaining ws_send,
  the automatic RFC 6455 handshake, and plain-JS client connection.
- Stream tour: second code block below the UDP examples shows the
  full UDP → resample → ws_send pipeline so visitors see the
  end-to-end browser-dashboard use-case at a glance.

https://claude.ai/code/session_014KkcPe2ttDpPoJBPTn7ijP
@bobjansen bobjansen merged commit 679d4ed into main Mar 7, 2026
1 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants