Skip to Content

SDK Initialisation & Handshake

This document describes the current initialization and handshake flow in the PlayServ Unity SDK.


Client-side initialization flow

  1. Configure SDK settings.
  2. Call PlayServ.Connect().
  3. SDK opens websocket transport and performs handshake.
  4. On success, state becomes Online.

Minimal setup:

PlayServ.Config( gameAccessToken: "your-token", gameId: "game-001", userId: "player-001", gameVersion: "1.0.0"); var connected = await PlayServ.Connect();

Extended setup:

var settings = new PlayServSettings { GameAccessToken = "your-token", GameId = "game-001", UserId = "player-001", GameVersion = "1.0.0", SdkVersion = "0.1.0", AllowMultipleConnections = true, KeepAlivePingIntervalMs = 30000, KeepAlivePongTimeoutMs = 10000, RemoteEndpoint = PlayServSettings.DefaultRemoteEndpoint }; PlayServ.Config(settings); var connected = await PlayServ.Connect();

Handshake inputs

Current handshake-relevant fields come from PlayServSettings:

  • GameAccessToken
  • GameId
  • UserId
  • GameVersion
  • SdkVersion
  • AllowMultipleConnections

If required values are missing, SDK throws configuration errors before connect.


KeepAlive and connection health

You can monitor keepalive activity:

PlayServ.OnKeepAlivePingSent += () => Debug.Log("[PlayServ] Ping sent"); PlayServ.OnKeepAlivePongReceived += () => Debug.Log("[PlayServ] Pong received");

Error handling

Use transport errors to inspect handshake rejection and policy failures:

PlayServ.OnTransportError += error => { Debug.LogError($"PlayServ transport error: {error.Code} - {error.Message}"); };

Server/in-process bootstrap (without websocket)

For server runtime or tests, register local handlers:

using Playserv.RPC; using Playserv.Server; using Playserv.Wrapper; public static class PlayServServerBootstrap { public static void Start() { var commandHandler = new LocalCommandHandler() .RegisterModule("server.match.create", command => { // Handle command locally. }); var eventHandler = new LocalEventHandler(); var rpcInvoker = new LocalRpcInvoker() .RegisterService(new NotificationService()); PlayServ.SetCommandHandler(commandHandler); PlayServ.SetEventHandler(eventHandler); PlayServ.SetRpcInvoker(rpcInvoker); } public static void Stop() { PlayServ.SetCommandHandler(null); PlayServ.SetEventHandler(null); PlayServ.SetRpcInvoker(null); PlayServ.Disconnect(); } }

Summary

Initialization in current SDK is Config -> Connect. Handshake and keepalive are internal runtime concerns; state and errors are exposed through PlayServ.State and transport callbacks.

Last updated on