Skip to main content

Reconnection Mechanism and Reconnection Mutual Kick

Automatic Reconnection Mechanism

The SDK has implemented an automatic reconnection mechanism. Once the connection is successful, the SDK's reconnection mechanism will immediately take effect and handle all reconnection processes. When the connection is lost due to network issues, the SDK will attempt to re-establish the connection internally, without requiring any additional connection operations from you.

Possible abnormal situations that may cause the SDK to disconnect and reconnect include:

  • Weak Network Environment: The SDK may continuously attempt to reconnect. Since there is a keep-alive mechanism between the client SDK and the RC server, if the network is too poor and causes a heartbeat timeout, the SDK will trigger a reconnection operation and keep trying until the connection is successful.
  • No Network Environment: The SDK's reconnection mechanism will pause. Once the network is restored, the SDK will attempt to reconnect.
tip

Once the connection error callback is triggered, the SDK will exit the reconnection mechanism. Please handle it according to the specific status code.

Reconnection Time Intervals

When the SDK attempts to reconnect, the time intervals increase progressively: 0s, 0.25s, 0.5s, 1s, 2s, 4s, 8s, 16s, 32s. After that, it retries every 64s.

When the app switches to the foreground or the network status changes, the reconnection time will start over from the above intervals to ensure a quick connection in such scenarios.

Manually Exit the Reconnection Mechanism

After the app actively disconnects, the SDK will exit the reconnection mechanism and no longer attempt to reconnect.

Reconnection Mutual Kick Policy

The reconnection mutual kick policy controls whether the device needs to be kicked offline when the SDK automatically reconnects successfully.

By default, the IM service only allows a single user account to log in on one mobile device at a time. Once a later mobile device connects successfully, the previously logged-in device will be automatically kicked out. In some cases, the SDK's reconnection mechanism may prevent the later device from staying online.

For example, the default reconnection mutual kick policy may lead to the following scenario:

  1. User Zhang San attempts to log in on mobile device A, but due to unstable network on device A, the connection fails, triggering the SDK's automatic reconnection mechanism.
  2. The user then attempts to log in on mobile device B. Device B connects successfully, and the user can use the IM service normally on device B.
  3. Once the network on device A stabilizes, the SDK reconnects successfully. Since device A is the later device to connect, device B is kicked out.

Modify the Reconnection Mutual Kick Policy for App Users

If the app user wants to keep device B logged in while kicking out device A in the above scenario, they can modify the reconnection mutual kick policy for the current user (User ID).

tip

Before using this interface, you must enable Allows the client SDK to adjust the reconnection strategy in the RC Console under Configuration > Chat settings > Basic features > Others.

Set whether to kick out the reconnecting device when the connection is lost. This configuration is part of the engine settings and must be set before initializing the engine.

RCIMIWEngineOptions options = RCIMIWEngineOptions.create();
options.kickReconnectDevice = true;
RCIMIWEngine engine = await RCIMIWEngine.create(appKey, options);

Parameter Description

ParameterTypeDescription
kickReconnectDeviceboolWhether to kick out the reconnecting device. See the detailed explanation of the kickReconnectDevice parameter below.

Detailed Explanation of the kickReconnectDevice Parameter:

  • Set to true:

    If another mobile device is already online during reconnection, the reconnection will not proceed, and the currently logged-in mobile device will not be affected.

  • Set to false:

    If another mobile device is already online during reconnection, the currently logged-in mobile device will be kicked out, allowing the reconnecting device to go online.