A和B通讯,这边通过for循环100次,A向B随机发送消息,测试了几次,发现跑不完这个循环就报错了。

Error: Command Timeout [cmd:2 op:null]
at createError (/Users/horsen/horsen_root/horsen_home/project/mynest/node_modules/leancloud-realtime/dist/realtime.js:2720:13)
at Timeout.onTimeout (/Users/horsen/horsenroot/horsen_home/project/mynest/node_modules/leancloud-realtime/dist/realtime.js:2816:28)
at listOnTimeout (internal/timers.js:531:17)
at processTimers (internal/timers.js:475:7) {
code: undefined,
appCode: undefined,
detail: undefined,
name: undefined
}

代码:

for(let i=0;i<count;i++){
    let currentKeyword = keyword[Math.floor(Math.random()*keyword.length)];
    this.myconversation.send(new TextMessage(currentKeyword)).then(function(message) {
          console.log("NO:"+i+"次发送成功,这次的关键词为:"+currentKeyword);
   }).catch(console.error);

}

通过 REST API 发送消息有次数限制3,但是通过客户端 SDK 发送消息不受此限制。

但是如果发送消息非常频繁的话,因为并发线程数的限制,后端可能来不及处理消息,从而导致超时。

如果您的应用是开发版的话,建议升级商用版(商用版并发线程数限制宽松很多),或者您也可以控制下发送消息的频率。

1.如果有N人同时发一条消息给A,这种情况N人只发一条是不会限制的吧?假设N人都发出来了,我想知道A这端能否全部接收到这些消息?

2.假设A客户端要给N个其他的客户端发消息,会限制发消息的目标客户端数量吗?还是只判断A的发送动作频率(由于您说的线程限制)?

客户端是没有发送消息的次数限制的。