Reconnect Mechanism

ParaSpace is an online virtual social platform that requires an active internet connection to access. Most of the time, players have stable and high-speed internet connections. However, network instability occurs occasionally, resulting in "network disconnections". Players may exit the room directly, leading to a negative gaming experience. To provide users with a better experience during network fluctuations, the ParaSpace SDK provides a Reconnect mechanism. Creators can improve players' experience with network disconnections and reconnections. This article introduces knowledge related to the Reconnect mechanism.

What Is the Reconnect Mechanism?

When there is an issue with a player's network connection, the player's client will not be able to receive any message from the server. At this time, the client will enter the "Disconnected" state, and a loading spinner icon will appear on the client. During this period, input by the player is disabled.

After entering the "Disconnected" state, the player's client will continuously attempt to reconnect to the server. Once successfully connected, the player's client will trigger a "reconnection success" event and receive necessary synchronized information such as other players' latest positions. At this time, the player can resume controlling his/her character. If network instability persists, a "reconnection failure" event will be triggered and the player will be removed from the room.

How Does the Reconnect Mechanism Work?

The Reconnect mechanism involves 2 stages and 2 nodes:

  • Stage 1 (network exception): The player's network begins to experience exceptions, such as disconnection or weak network environment.
  • Node 1 (disconnection event): When the client detects a network exception (such as disconnection, the client receiving no messages from the server for 5 seconds, or the server receiving no messages from the client for 5 seconds), it triggers a "disconnection" event and operations by the player are disabled.
  • Stage 2 (attempt to reconnect): The client and server will attempt to reconnect, which usually continues for about 30 seconds.
  • Node 2 (reconnection success/failure event): If the reconnection is successful, the client triggers a "reconnection success" event, and the player can resume operations and receive the latest synchronized data from the server. If the reconnection fails, the client triggers a "reconnection failure" event, the player will exit the platform, and other players in the room will see that the player has left.

Network ownership transfer:

  • When a disconnection event occurs, if the disconnected player is the network master, a new network master will be appointed and the player's ownership will be transferred to the new network master.

APIs related to disconnection and reconnection events:

  • When a disconnection event occurs, the disconnected player will receive the OnDisconnected event.
  • When a reconnection success event occurs, the disconnected player will receive the OnReconnect event.
  • When a reconnection failure event occurs, other players will receive the OnPlayerLeft event of the disconnected player.

Disable the Reconnect Mechanism

In general, to implement complex game logic, special handling is required for network reconnection scenarios to ensure a good player experience. However, if this is too hard for you and you want to do this later, you can disable the Reconnect mechanism and simplify the game logic.

To disable the Reconnect mechanism, call the ParaNetService.DisableReconnection API.

After you disable the Reconnect mechanism, if a disconnection event occurs, the disconnected player will be returned to the platform.