Reconnection Mechanism and Reconnection Kick Strategy
Automatic Reconnection Mechanism
The SDK has implemented an automatic reconnection mechanism. Once the connection is successfully established, the SDK's reconnection mechanism will take effect immediately 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 scenarios that may trigger the SDK's reconnection mechanism 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.
Once the connection error callback is triggered, the SDK will exit the reconnection mechanism. Please handle it based on the specific status code.
Reconnection Interval
When the SDK attempts to reconnect, the time interval increases progressively: 0.05s (0s before version 5.6.2), 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 interval will restart from the beginning to ensure a quick reconnection in such scenarios.
Manually Exiting the Reconnection Mechanism
After the app actively disconnects, the SDK will exit the reconnection mechanism and will no longer attempt to reconnect.
Reconnection Kick Strategy
The reconnection kick strategy controls whether the SDK should kick out other devices when it successfully reconnects.
By default, the IM service only allows a single user account to log in on one mobile device at a time. When a new mobile device successfully connects, it will automatically kick out the previously logged-in device. In some cases, the SDK's reconnection mechanism may prevent the newly logged-in device from staying online.
For example, the default reconnection kick strategy may lead to the following scenario:
- User Zhang San attempts to log in on mobile device A, but due to unstable network conditions on device A, the connection fails, triggering the SDK's automatic reconnection mechanism.
- The user then attempts to log in on mobile device B. Device B successfully connects, and the user can use the IM service normally on device B.
- When the network on device A stabilizes, the SDK reconnects successfully. Since device A is the last device to come online, device B is kicked out.
Modifying the Reconnection Kick Strategy for App Users
If the app user wishes to kick out device A when it reconnects successfully while keeping device B logged in, they can modify the reconnection kick strategy for the current user (User ID
).
Before using this interface, you must enable Allow SDK to Modify Reconnection Kick 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 method needs to be called before init.
[[RCIMClient sharedRCIMClient] setReconnectKickEnable:YES];
Parameter | Type | Description |
---|---|---|
enable | boolean | Whether to kick out the currently reconnecting device. See the enable Parameter Details below. |
enable
Parameter Details:
-
Set
setReconnectKickEnable
to YESIf a reconnection attempt finds another mobile device already online, the reconnection will be aborted, and the already logged-in mobile device will remain unaffected.
-
Set
setReconnectKickEnable
to NOIf a reconnection attempt finds another mobile device already online, the already logged-in mobile device will be kicked out, allowing the current device to come online.