我的客户端socket
有一个名为socket.acks
的属性。该属性不断增长,几分钟之内,其中就有超过 5000 个条目。
它们看起来像这样:
acks:
{ '11': [Function],
'12': [Function],
'13': [Function],
'14': [Function],
'15': [Function],
'16': [Function],
'17': [Function],
}
编辑
我的服务器充当在两个客户端之间发送信息的代理。
服务器
// Assume client1 is a reference to client1 socket, and client2 is for client2
socket.on('on_data_from_client1', function (data, cb) {
// Here data and cb are sent to client2.
// I guess this is causing the .acks to be added since I am
// passing a function as last parameter to .emit.
// But It is not me who should worry about the callback, but rather client2
client2.emit('data_from_client1', data, cb);
});
最佳答案
查看代码,这是一个包含未确认消息的对象。
一旦消息被确认,它将从此对象中删除,因此我猜测您的客户端在服务器期望发生确认时没有确认消息。
更多信息here .
编辑
我从未使用过类似的设置,所以不知道它是否应该工作(我预见当其中一个客户端断开连接时会出现未确认消息的问题,尽管我还没有足够仔细地查看 socket.io
实现来查看在这种情况下是否会正确清理任何待处理的确认)。
我现在能想到的唯一可能的解决方案是这个(尽管它的功能与你的相同):
socket.on('on_data_from_client1', function (data, cb) {
client2.emit('data_from_client1', data, function(moreData) {
return cb(moreData);
});
});
关于javascript - Socket.io 中的 `.acks` key 是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32277430/