I have multiple servers in multiple locations. I need to get the frequency at which the websocket messages are received. When I connect to a low-latency server, the frequency is normal (50 - 60 ms). But on high latency servers, the frequency sometimes is 0. I asked a similar question not to long ago, but the answer there was that the socket is buffering messages. I find this unlikely since it only happens on high latency servers.
Here is the code responsible for handling the websocket:
startTime = Date.now();
ws.onmessage = function (evt)
{
prevData = recivedData;
var receivedMsg = evt.data;
recivedData = JSON.parse(receivedMsg);
const endTime = Date.now();
ms = endTime - startTime;
startTime = endTime;
if(msAvg == null){
msAvg = ms;
}
msAvg = Math.round(((msAvg * 5) + ms) / 6);
id = recivedData.id;
}
ms
is the frequency in milliseconds.
How can I get to the bottom of this issue?