WebSocket for Unity
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.
Connect a Unity Game to Backend Events
A lobby, chat channel, or turn-action service can exchange small application messages with Staxis. Choose the client transport for the actual build target before designing its receive loop. The payload below is the shared echo contract, not Unity Netcode replication.
{
"v": 1,
"action": "echo",
"requestId": "demo-1",
"data": { "text": "hello" }
}
Native Builds
Where the target supports ClientWebSocket, keep one receive loop and serialize sends. Accumulate receive chunks until EndOfMessage before decoding a text message. Pass validated results to the game's main-thread update flow rather than treating each receive buffer as a complete game action. See ClientWebSocket.ReceiveAsync and EndOfMessage.
Web Builds
Unity Web builds use browser networking restrictions, so do not assume the native .NET socket path works there. Use a browser WebSocket integration appropriate to the project, and apply the same browser handshake checks as a Webgame. Unity's Web networking manual describes the platform boundary.
Keep Game Rules Explicit
Validate player identity and allowed actions on the server, bound queued input, and define reconnect and state-resynchronization rules. A WebSocket connection by itself does not implement Unity Transport, Netcode messages, room ownership, or authoritative simulation. Start by verifying the echo round trip from each target build, then add one authenticated game action.