API Reference of GS2-Gateway SDK for Game Engine

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

Model

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.

TypeConditionRequiredDefaultValue LimitsDescription
connectionIdstring
~ 128 charsconnection ID
namespaceNamestring
~ 128 charsNamespace name
userIdstring
~ 128 charsUser ID

Methods

setUserId

Set user ID to receive push notifications from the server

Request

TypeConditionRequiredDefaultValue LimitsDescription
namespaceNamestring
~ 128 charsNamespace name
gameSessionGameSession
GameSession
allowConcurrentAccessbool
trueWhether to allow connections from different clients at the same time
sessionIdstring{allowConcurrentAccess} == false~ 128 charsSpecifies a session ID that allows reconnection when allowConcurrentAccess is false and the existing connection has the same session ID.
* Enabled if allowConcurrentAccess is false

Result

TypeDescription
itemEzWebSocketSessionWebSocket 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();