简体   繁体   English

什么是Socket.io中的.acks键

[英]What is the `.acks` key in Socket.io

My client socket has a property called socket.acks . 我的客户端socket具有一个名为socket.acks的属性。 This property continuously grows, and within a few minutes, there are over 5000 enteries in it. 此属性不断增长,并且在几分钟之内就有5000多个肠。

They look something like this: 他们看起来像这样:

acks:
   { '11': [Function],
     '12': [Function],
     '13': [Function],
     '14': [Function],
     '15': [Function],
     '16': [Function],
     '17': [Function],
   }

EDIT 编辑

My server acts as a proxy to sending information between two clients. 我的服务器充当两个客户端之间发送信息的代理。

Server 服务器

// 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);
});

Looking through the code, it's an object that contains unacknowledged messages. 查看代码,它是一个包含未确认消息的对象。

Once a message has been acknowledged, it will be removed from this object, so I'm guessing that your client isn't acknowledging messages while the server is expecting acknowledgement to happen. 确认消息后,将从该对象中删除该消息,因此我猜测您的客户端没有在服务器期望发生确认的同时确认消息。

More information here . 更多信息在这里

EDIT 编辑

I've never used a similar setup so no idea if it's supposed to work at all (I foresee issues with unacknowledged messages when one of the clients disconnects, although I haven't looked close enough at the socket.io implementation to see if any pending acks will be cleaned up properly in that case). 我从来没有使用过类似的设置,所以根本不知道它是否应该工作(我预见到其中一个客户端断开连接时出现未确认消息的问题,尽管我对socket.io实现还不够仔细。在这种情况下,待处理的袜子将被正确清理)。

The only possible solution I can think of right now is this (although it's functionally the same as yours): 我现在能想到的唯一可能的解决方案是(尽管它在功能上与您的相同):

socket.on('on_data_from_client1', function (data, cb) {
  client2.emit('data_from_client1', data, function(moreData) {
    return cb(moreData);
  });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM