0
votes

I am using MongooseIM as chat server and connecting it over websocket using xmpp.js inside react-native application. The server forcefully closes the connection after 60s on inactivity. I want to know:

  1. If this is the default config?
  2. Should/Can I change it?
  3. Should I set up ping mechanism such that my client must send some pings after every 60s to avoid disconnect
1
Do you have mod_ping aka XMPP Ping enabled on the server, but not on the client? 60 seconds is the default ping interval for both MongooseIM and ejabberd, so it seems a likely culprit.erszcz
Yes, i have tried the mod_ping module. But the connection always closes irrespective of mod_ping used or not inside the chrome browser and sometimes in the react-native apps also. Don't know why?Shubham1164
I guess this is some limitation or safety factor for web socket conn. Not sureShubham1164
TCP connections being closed might stem from a lot of factors, e.g. your network environment. Are you running the server on Amazon? If yes, this might apply to your case - stackoverflow.com/a/48764819/1325207. What @michalwski says below might also apply.erszcz

1 Answers

2
votes

WebSocket connections have default timeout value for inactivity set to infinity. Your configuration most probably contains "{timeout, 60000}" in the "mod_websockets" configuration. In order to keep idle connections connected to the server you can send WebSocket ping frames from time to time.

More info about "mod_websockets" configuration is here:: https://mongooseim.readthedocs.io/en/latest/advanced-configuration/Listener-modules/#http-based-services-bosh-websocket-rest-ejabberd_cowboy

You can even configure the server to send WebSocket's ping frames by specifying the option {ping_rate, ValueInMilliSeconds}