Skip to main content
Version: 4.x

教程 - 处理断开连接


现在,让我们重点介绍 Socket.IO 的两个非常重要的属性:

英:Now, let's highlight two really important properties of Socket.IO:

  1. Socket.IO 客户端并不总是处于连接状态
  2. Socket.IO 服务器不存储任何事件


英:Even over a stable network, it is not possible to maintain a connection alive forever.


英:Which means that your application needs to be able to synchronize the local state of the client with the global state on the server after a temporary disconnection.


Socket.IO 客户端将在短暂延迟后自动尝试重新连接。 然而,对于该客户端来说,在断开连接期间任何遗漏的事件都将实际上丢失。

英:The Socket.IO client will automatically try to reconnect after a small delay. However, any missed event during the disconnection period will effectively be lost for this client.


英:In the context of our chat application, this implies that a disconnected client might miss some messages:

The disconnected client does not receive the 'chat message' eventThe disconnected client does not receive the 'chat message' event


英:We will see in the next steps how we can improve this.