Skip to content

Update C# sdk to use v3 websocket api#4763

Open
joshua-spacetime wants to merge 3 commits intojoshua/ws/v3from
joshua/csharp/v3-ws-bindings
Open

Update C# sdk to use v3 websocket api#4763
joshua-spacetime wants to merge 3 commits intojoshua/ws/v3from
joshua/csharp/v3-ws-bindings

Conversation

@joshua-spacetime
Copy link
Copy Markdown
Collaborator

@joshua-spacetime joshua-spacetime commented Apr 9, 2026

Description of Changes

This PR adds C# SDK support for the v3.bsatn.spacetimedb WebSocket transport which was added in #4761 and keeps v2 as a fallback.

v3 is just a transport wrapper around already-encoded v2 logical messages:

  • the client offers v3 first and falls back to v2 during handshake when needed
  • when v3 is negotiated, outbound client messages are batched into a single transport frame
  • v3 batching is capped at 256 KiB per frame
  • after sending one capped v3 frame, the send pump schedules a follow-up pass using the SDK’s existing scheduling primitives rather than draining the entire queue in one uninterrupted pass
  • inbound v3 server frames are unwrapped into their inner v2 messages and then processed by the existing v2 parse/apply pipeline in order

This also includes Unity WebGL transport updates so the C# SDK can:

  • offer multiple WebSocket subprotocols
  • observe the negotiated protocol
  • switch send/receive transport behavior accordingly

API and ABI breaking changes

None. Existing servers that only support v2 continue to work because the SDK falls back during handshake.

Expected complexity level and risk

3

The main risks are:

  • preserving message ordering when multiple logical messages share one v3 frame
  • preserving fallback behavior for v2
  • keeping the capped batching behavior from starving other websocket work
  • keeping WebGL protocol negotiation and callback marshalling correct

The risk is limited by keeping the existing v2 logical message pipeline intact underneath the new transport layer.

Testing

Integration tests for v3 and v2 fallback

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.

1 participant