WebSocket connection failed after idle

RE: Connection Status

I noticed that the connection failed after the app idles. I’m aware that after the connection failed, the SDK will automatically reconnect to the WebSocket. However, sometimes it’s not working even there’s an active internet connection.

After I restart the app, I was able to reconnect to the WebSocket again. That said, is there a way to manually reconnect to the WebSocket?

Please note that we are using the latest iOS SDK version (2.0.13 Xcode 11).

It looks this issue is related to this one.

Any idea? @pushpsen.airekar @jeet.kapadia

Hello @srbalan,

We are checking this at our end and will get back to you as soon as we have an update on this. Please provide us some time for the same. Appreciate your patience.

Warm Regards,

CometChat Pro
Mayur Bhandari

1 Like

Hello @srbalan,

Yes. You can handle this in AppDelegate. You just need to call CometChat.init Method whenever app enters in foreground.

This simple trick will resolve your issue.


Thank you so much :grinning:

By the way @pushpsen.airekar, should I use CometChat.initialize() or CometChat with parameters (App ID and App Settings) ?

Hello @srbalan,

Same method you’ve to use which you’re using with AppSettings.


Hi @pushpsen.airekar
Even the app was not idled or went to background, I’m still experiencing frequent connecting status. Is this a server issue or SDK?

Also, please note that re-initializing the CometChat doesn’t solve the issue.

I tried to re-init the CometChat whenever app enters foreground. Also, I tried to re-init when the status is connecting or disconnected.

The initialization is successful but the status connection status doesn’t change.

Any updates @pushpsen.airekar?

@jeet.kapadia any idea?

Hi @srbalan,

I have checked the scenario however I was not able to replicate the same. I tried this in our iOS Swift Chat app and I was able to receive messages even after keeping the device for idle time of about 20 mins. When the device was idle the connection was not interrupted and everything was working as expected. Also, to answer your question there is no manual way to reconnect to the WebSocket. We have internally handled everything to make sure that the SDK reconnects in events of disconnection.

Jeet Kapadia

Hi @jeet.kapadia
Thank you for checking. May I know which CometChat SDK version did you use?

Hi @srbalan,

I have checked this with our latest live stable version 2.0.13-Xcode11.6. Also, I have checked this in our swift sample app. Here is the link of the app:

Let me know if you require anything else. I would be happy to assist you.

Jeet Kapadia

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.