Flask-SocketIO: Server doesn't receive disconnect event
Server-side disconnect event is never triggered when Android app loses WiFi connectivity, for instance if I shutdown WiFi manually or if I turn off Android phone.
I’ve adjusted the Server side params and now the client detects the disconnection, but not the server:
params = {
'ping_timeout': 10,
'ping_interval': 5
}
socketio = SocketIO(**params)
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 28 (14 by maintainers)
@miguelgrinberg I’m getting disconnects too! First time being so happy about “disconnection” 😃 👍 Good job, and thank you a lot
@NamanJain2050 the disconnection will occur in at most 60 seconds, it could happen sooner. You are actually using python-engineio because Flask-SocketIO uses it.
python-engineio 1.5.0 with this fix is now on pypi. Thanks for all your help!
@miguelgrinberg my
pip freezeoutputs:And I checked
engineio’s source code located invenv/lib/python3.6/site-packages/engineio, it does match your latest commit 9a9689, in which 3 files are modified:async_eventlet.py,asyncio_socket.pyandsocket.py.By the way I’m using Python 3.6.1, if that matters.
I’ve been playing with a Chrome client on Android and found the following:
This behavior can be seen when using eventlet or gevent, and is also present with other websocket servers.
To detect those disconnections, the server will need to keep track of PING packets sent by clients, like it does for long-polling. Any clients that haven’t sent a PING packet in more time than the configured
ping_interval, will be disconnected. Unfortunately this means that a client that loses its connection abruptly will be declared disconnected after 60 seconds in the worst case, when using the default ping interval. The disconnect may be detected earlier if the server needs to send an event to that client.