Skip to main content

Reconnection Mechanism and Multi-Device Kick Policy

Automatic Reconnection Mechanism

The SDK has a built-in automatic reconnection mechanism. Once connected, this mechanism takes effect immediately and handles all reconnection processes. When disconnection occurs due to network issues, the SDK will automatically attempt to re-establish the connection without requiring additional manual operations.

Common scenarios that may trigger SDK reconnection include:

  • Weak network conditions: The SDK may continuously attempt reconnection. Since there's a keep-alive mechanism between the client SDK and RC servers, if poor network quality causes heartbeat timeouts, the SDK will initiate reconnection attempts until successful.
  • No network connectivity: The reconnection mechanism pauses temporarily. Once network connectivity is restored, the SDK will resume reconnection attempts.
  • App running in background: The IMKit SDK actively disconnects when the app remains in the background for more than 2 minutes or when suspended by the system. The IMKit SDK will trigger reconnection when the app returns to the foreground.
tip

When connection error callbacks are triggered, the SDK exits the reconnection mechanism. Please handle these cases manually based on specific status codes.

Reconnection Interval

The SDK uses progressively increasing intervals for reconnection attempts: 0.05s (0s before v5.6.2), 0.25s, 0.5s, 1s, 2s, 4s, 8s, 16s, 32s, followed by 64s intervals for subsequent attempts.

When the app returns to the foreground or network status changes, the reconnection interval resets to the initial sequence to ensure quick reconnection.

Manual Exit from Reconnection Mechanism

When the app actively disconnects, the SDK exits the reconnection mechanism and stops further attempts.

Multi-Device Kick Policy

This policy determines whether previously connected devices should be kicked when the SDK automatically reconnects.

By default, RC Chat only allows a single user account to be logged in on one mobile device at a time. When a new mobile device connects successfully, it automatically kicks out any previously connected device. In some cases, the SDK's reconnection mechanism may prevent newly connected devices from staying online.

For example, the default policy may lead to this scenario:

  1. User Zhangsan attempts to log in on Device A, but fails due to unstable network, triggering the SDK's automatic reconnection mechanism.
  2. The user then logs in successfully on Device B and can use RC Chat normally.
  3. When Device A's network stabilizes and reconnects successfully, it becomes the "newer" device, causing Device B to be kicked offline.

Modifying Reconnection Kick Policy

If you want Device A to be kicked while keeping Device B online in such scenarios, you can modify the reconnection kick policy.

tip

IMKit doesn't provide direct API for this. If needed, call the IMLib SDK's setReconnectKickEnable method. See IMLib documentation: Reconnection Mechanism and Multi-Device Kick Policy.