GS2-Realtime

Real-time communication function

This feature can be used for low-latency, high-frequency communication to allow game players to play against each other.

GS2 typically charges by the number of API requests, but for this service, once the game server is up and running, a fee is charged for the time the game server is up and running and for communication capacity.

Server Type

Currently, GS2-Realtime only provides packet relay functionality. This is based on the ability to send a message to a game server, which will then send the message to other players. It only has the ability to specify a player ID and deliver the message to the specified player.

The SDK does not include features such as RPC or object synchronization, only the ability to send and receive simple binary data.

Unreal Engine Dedicated Server Hosting

We are looking into the possibility of allowing developers to host a dedicated server built with the Unreal Engine. We have not yet decided when this feature will be available.

We can recommend development with a paid support contract, and if there is a strong need, we can work out a schedule.

Server Specs

You can set the performance of the server. The performance will make a difference in the price per minute. We have confirmed that the cheapest realtime1.nano can send messages to each other 3 times per second with 8 players.

The Unreal Engine Dedicated Server hosting we are considering will have higher requirements. Unreal Engine Dedicated Server is not recommended for projects where cost efficiency, not development efficiency, is paramount.

Life Cycle

A game server is not scheduled to start until it receives a startup request.

At this point, GS2 will prepare a hot standby for game servers that receive frequent startup requests. Therefore, it is expected that the assignment will take place immediately after a startup request is accepted, but for small games that do not generate frequent startup requests, it will take time from the startup request to the actual assignment.

We refer to the case where the allocation is done from a hot standby as a warm start, and the case where the allocation is done by starting a new server as a cold start. The estimated time required for cold start allocation is about 40 to 60 seconds, while the time required for warm start allocation is assumed to be 1 to 3 seconds.

For titles of a size that do not generate frequent start requests and where cold start time is unacceptable Hot Standby can be provided on the assumption that a fixed monthly fee will be charged. We accept contracts for hot standby with a minimum of 5 units.

We cannot guarantee that cold starts will not occur even if you have a hot standby contract or in situations where frequent startup requests occur. Cold starts can occur if server startup requests are made before hot standby is available or if the game server is being upgraded. Therefore, please design your system with the worst-case scenario of a cold start in mind.

Profile

Relay servers not only forward received messages to other players, but also allow each player to have profile information.

When a new player connects to the game server, he/she will receive profile information for all other participating players. Storing basic player information simplifies the process when a new player connects.

When a player updates their profile, the information is sent to other players, so it can be used as a substitute for sending a message. However, it is not optimal in terms of communication efficiency to use high-frequency messaging for profile updates, since the entire payload is sent and received when a profile is updated.

Example implementation

Obtaining connection information to the game server

    var item = await gs2.Realtime.Namespace(
        namespaceName: "namespace-0001"
    ).Room(
        roomName: "room-0001"
    ).ModelAsync();

    var ipAddress = item.IpAdress;
    var port = item.Port;
    var encryptionKey = item.EncryptionKey;

Connect to game server

    using (
      var session = new RelayRealtimeSession(
         accessToken, // アクセストークン
         ipAddress, // ゲームサーバのIPアドレス
         port, // ゲームサーバのポート
         encryptionKey, // 暗号鍵
         ByteString.CopyFromUtf8("my profile") // プロフィールの初期値
      )
    )
    {
      // イベントハンドラを設定

      await session.ConnectAsync();

      // セッションが有効なスコープ
    }
    const auto Domain = Gs2->Realtime->Namespace(
        "namespace-0001" // namespaceName
    )->Room(
        "room-0001" // roomName
    );
    const auto Future2 = Domain->Model();
    Future2->StartSynchronousTask();
    if (!TestFalse(WHAT, Future2->GetTask().IsError())) return false;
    const auto Result = Future2->GetTask().Result();

    const auto IpAddress = Result->GetIpAdress();
    const auto Port = Result->GetPort();
    const auto EncryptionKey = Result->GetEncryptionKey();

Handling connections from other players

    session.OnJoinPlayer += player => {

    };

Handling disconnections of other players

    session.OnLeavePlayer += player => {

    };

Handling messages from other players

    session.OnRelayMessage += message => {

    };

Handling profile updates of other players

    session.OnUpdateProfile += player => {

    };

Handling disconnects from game server

    session.OnClose += () => {

    };

Update Profile

    await session.UpdateProfileAsync(
      ByteString.CopyFromUtf8("my profile2")
    )

Send broadcast message

    await session.SendAsync(
      ByteString.CopyFrom(0x00, 0x01, 0x02)
    )

Send unicast message

    await session.SendAsync(
      ByteString.CopyFrom(0x00, 0x01, 0x02),
      new uint[] { targetConnectionId1, targetConnectionId2 }
    )

Detailed reference