GS2-Gateway SDK for Game Engine API Reference

Specifications of models and API references for GS2-Gateway SDK for Game Engine

Models

EzWebSocketSession

WebSocketSession

A WebSocket session is a persistent connection between a GS2 server and a client for real-time bidirectional communication. The client registers a user ID as an identifier to the server.

Type Condition Required Default Value Limits Description
connectionId string
~ 128 chars Connection ID
The unique identifier assigned to this WebSocket connection. Used to identify the specific client connection when sending notifications.
namespaceName string
~ 128 chars Namespace name
userId string
~ 128 chars User ID

Methods

setUserId

Register the player’s connection to receive server push notifications

Links the current WebSocket connection to the player’s user ID so that the server can send real-time push notifications to this client. This is typically called right after the player logs in and connects to the server — without this step, the server won’t know which connection belongs to which player. The allowConcurrentAccess flag controls whether the same player can be connected from multiple devices at once:

  • true: allows multiple simultaneous connections (e.g., playing on both phone and tablet)
  • false: only one connection per player is allowed (e.g., to prevent duplicate logins — the old connection gets kicked) Use this as part of your game’s login/initialization flow to enable features like real-time chat notifications, friend request alerts, or match-found notifications.

Request

Type Condition Required Default Value Limits Description
namespaceName string
~ 128 chars Namespace name
gameSession GameSession
GameSession
allowConcurrentAccess bool true Whether to allow connections from different clients at the same time
sessionId string {allowConcurrentAccess} == false ~ 128 chars Specifies a session ID that allows reconnection when allowConcurrentAccess is false and the existing connection has the same session ID.
* Enabled only if allowConcurrentAccess is false

Result

Type Description
item EzWebSocketSession WebSocket session updated

Implementation Example

    var domain = gs2.Gateway.Namespace(
        namespaceName: "$hash"
    ).Me(
        gameSession: GameSession
    ).WebSocketSession(
    );
    var result = await domain.SetUserIdAsync(
        allowConcurrentAccess: true,
        sessionId: null
    );
    var item = await result.ModelAsync();
    var domain = gs2.Gateway.Namespace(
        namespaceName: "$hash"
    ).Me(
        gameSession: GameSession
    ).WebSocketSession(
    );
    var future = domain.SetUserIdFuture(
        allowConcurrentAccess: true,
        sessionId: null
    );
    yield return future;
    if (future.Error != null)
    {
        onError.Invoke(future.Error, null);
        yield break;
    }
    var future2 = future.Result.ModelFuture();
    yield return future2;
    if (future2.Error != null)
    {
        onError.Invoke(future2.Error, null);
        yield break;
    }
    var result = future2.Result;
    const auto Domain = Gs2->Gateway->Namespace(
        "$hash" // namespaceName
    )->Me(
        GameSession
    )->WebSocketSession(
    );
    const auto Future = Domain->SetUserId(
        true // allowConcurrentAccess
        // sessionId
    );
    Future->StartSynchronousTask();
    if (Future->GetTask().IsError())
    {
        return false;
    }

    // obtain changed values / result values
    const auto Future2 = Future->GetTask().Result()->Model();
    Future2->StartSynchronousTask();
    if (Future2->GetTask().IsError())
    {
        return Future2->GetTask().Error();
    }
    const auto Result = Future2->GetTask().Result();