If you exit the mobile browser, websocket will shut down automatically. Won't it last for a long time?

Before

, websocket had the problem of shutting down itself.
so I nginx used:

location /wss {  -sharp websocket
proxy_read_timeout  36000s;

doesn"t seem to have any effect.

so I regularly send client requests at the front end:

 setInterval(() => {
     ws.send(JSON.stringify(params));
  }, 50000);
  

is effective.

but once mobile browsers switch to other applications, websocket will automatically close after 50 seconds.
I wonder why websocket or http protocols are all keep-alive persistent connections

.

applications on mobile phones, including browsers retreating to the background, are usually suspended by the operating system. It seems that Chrome on Android will turn on websockets, but it will completely pause the timer when the screen is turned off. This causes the device to disconnect when the server-side heartbeat times out, and because the heartbeat timer is not running on the client, it will continue to reconnect and disconnect. Functions such as keeping connected are best implemented through native services.

here is a list of background performances for reference

Mobile devices can have different behaviour:

in background tabs
when display is turned off
This ticket is to track state of things

Timers at mobile devices

< table > < thead > < tr > < th > Browser < / th > < th > Background < / th > < th > Display off < / th > < th > Background WW < / th > < th > Display off WW < / th > < / tr > < / thead > < tbody > < tr > < td > Android browser < / td > < td > OK < / td > < td > fail < / td > < td > OK < / td > < td > fail < / td > < / tr > < tr > < td > Android FF < / td > < td > fail < / td > < td > fail < / td > < td > OK < / td > < td > OK < / td > < / tr > < tr > < td > Android Chrome < / td > < td > OK < / td > < td > OK < / td > < td > OK < / td > < td > OK < / td > < / tr > < tr > < td > iOS Chrome < / td > < td > OK < / td > < td > fail < / td > < td > OK < / td > < td > fail < / td > < / tr > < tr > < td > iOS Safari < / td > < td > fail < / td > < td > fail < / td > < td > fail < / td > < td > fail < / td > < / tr > < / tbody > < / table >

iOS Safari-sometimes timer in background can continue working 0-20 seconds
iOS Safari-foreground tab continue working 10-15 seconds after display turned off
Conclusion
Everything is bad on ios. The only solution is to reselect master.
On android things are acceptable, if you generate timer events from WebWorker
SharedWorker will not help:
not supported in browsers with timer problems
not much needed in browsers without timer problems

the conclusion is that Chrome is not bad!


Thank you for the invitation.
learn about web offline solution ServiceWorker

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eafb08-4804e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eafb08-4804e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?