Answer the question
In order to leave comments, you need to log in
How to check if client has disconnected from Django websocket?
There is a task:
The client establishes Websocket with Django. I'm using django 2.0 and channels 2.1.1 . In channels, a task is launched that can take a very long time - requests are sent to different servers, and when responses are received, the processed information is sent to the socket to the client. If the client closed the page or the Internet fell off, the server does not determine this in any way, but continues execution as if the socket were alive. How to organize a client poll (sending a heartbeat), whether it is alive or has fallen off, and if it has fallen off, close the socket and stop the script execution?
Answer the question
In order to leave comments, you need to log in
It is enough to define the appropriate method in the handler :
class MyConsumer(AsyncWebsocketConsumer):
async def disconnect(self, close_code):
# соединение закрылось
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question