如何在客户端上处理快速传入的WebSocket消息

时间:2020-10-24 14:13:22

标签: javascript node.js performance websocket ws

以下问题。我正在尝试处理发送到我的客户的数据。我大约有100个开放订阅,它们几乎同时发送不同的数据到我的客户端,但是我需要一次处理它们。我该怎么办?

const ws = new WebSocket('wss:/xyz.com');


// Add a listener that will be triggered when the WebSocket is ready to use

ws.addEventListener('open', () => {
  console.log('Sending a request to the Server:', sendData);

  
// Send the message to the WebSocket server
  

ws.send(sendData);


});





// Add a listener in order to process WebSocket messages received from the server


ws.addEventListener('message', event => {

      let t1 = performance.now()
    
  //Using Zlib to decompress the responses
    
zlib.unzip(event.data, (err, buffer) => {
 
      fetchData(buffer)
        
      let t2 = performance.now()
        
      console.log(t2-t1);
    
})


});

现在 fetchData() 我经常收到邮件,甚至无法完成邮件,但我需要一一处理。我不知道该怎么做。

预先感谢:)

0 个答案:

没有答案