Django 频道如何知道客户端已断开连接?
how does django channels knows that a client has disconnected?
我担心客户端会突然断开连接并断开连接,而不会向后端留下任何信息。如果发生这种情况,套接字是否会保持活动状态?
我在 django 频道存储库的一个问题中找到了答案:
Using websocket auto-ping to periodically assert clients are still connected to sockets, and cutting them loose if not. This is a feature that's already in daphne master if you want to try it, and which is coming in the next release; the ping interval and time-till-considered-dead are both configurable. This solves the (more common) clients-disconnecting-uncleanly issue.
Storing the timestamp of the last seen action from a client in a database, and then pruning ones you haven't heard of in a while. This is the only approach that will also get round disconnect not being sent because a Daphne server was killed, but it's more specialised, so Channels can't implement it directly.
我担心客户端会突然断开连接并断开连接,而不会向后端留下任何信息。如果发生这种情况,套接字是否会保持活动状态?
我在 django 频道存储库的一个问题中找到了答案:
Using websocket auto-ping to periodically assert clients are still connected to sockets, and cutting them loose if not. This is a feature that's already in daphne master if you want to try it, and which is coming in the next release; the ping interval and time-till-considered-dead are both configurable. This solves the (more common) clients-disconnecting-uncleanly issue.
Storing the timestamp of the last seen action from a client in a database, and then pruning ones you haven't heard of in a while. This is the only approach that will also get round disconnect not being sent because a Daphne server was killed, but it's more specialised, so Channels can't implement it directly.