WebSocket for Godot
This is a draft integration guide for the Staxis WebSocket layer, not an engine-specific SDK. Start with the server-side echo path and the same versioned application message shape. Add player authentication and game-state authorization separately.
A Godot Lobby or Turn-Based Client
Use WebSocketPeer for a direct application protocol with Staxis. Connect to the mounted path, poll regularly, and send the echo contract as text after the peer reaches STATE_OPEN.
{
"v": 1,
"action": "echo",
"requestId": "demo-1",
"data": { "text": "hello" }
}
Polling and Packet Types
-
Call connect_to_url() for the chosen ws or wss endpoint, then keep calling poll() in the update flow.
-
Inspect get_ready_state() and send only in STATE_OPEN. Drain available packets with get_available_packet_count() and get_packet().
-
Use was_string_packet() to distinguish text from binary. Decode text as UTF-8 and validate its JSON shape; interpret binary only through the explicit application byte contract.
-
Continue polling while closing. Bound pending actions and recreate the authenticated application state after reconnect.
The WebSocketPeer reference documents polling, readiness, and packet access. Its text and binary methods should match the server's evt.type branch. The Godot WebSocket tutorial provides engine-side examples.
Keep the Application Protocol Separate
A Godot high-level multiplayer protocol needs a compatible server-side implementation; matching the WebSocket transport alone does not provide that. This draft uses direct messages and a custom server handler. Web exports also need the browser handshake checks. See the main binary-routing example if you add binary game events.