转到主要内容
Latest blog post (July 25, 2024): npm package provenance.
这是 Socket.IO 3.x, 不再积极维护。
有关最新文档,请参阅最新版本 (4.x).
版本:3.x

Offline behavior

Buffered events

By default, any event emitted while the Socket is not connected will be buffered until reconnection.

While useful in most cases (when the reconnection delay is short), it could result in a huge spike of events when the connection is restored.

There are several solutions to prevent this behavior, depending on your use case:

  • use the connected attribute of the Socket instance
if(socket.connected){
socket.emit(/* ... */);
}else{
// ...
}
socket.volatile.emit(/* ... */);
  • empty the internal buffer upon reconnection
socket.on("connect",()=>{
socket.sendBuffer=[];
});

AltStyle によって変換されたページ (->オリジナル) /