I'm working on a CCXT based app server on Node. I want to measure websocket connection latency between Node and remote exchanges. For this purpose I'd like to initiate a ping
right after websocket stream subscription and then repeat it periodically according to 'keepAlive' settings. Upon receipt of a reply pong
I could calculate the roundtrip time.
I can override the handler of the pong
s:
ex = new Exchange();
if(ex.handlePong)
{
const original_handler = ex.handlePong.bind(ex);
ex.handlePong = (ws, data) => { original_handler(ws, data); console.log("Pong at ", Date.now(), "after", ex.myPing); ... actual stuff here ...}
}
But I can't figure out how to send ping
s. The following attempts do not produce any effect:
if(!ex.myPing || Date.now() - ex.lastPong > 30000)
{
ex.myPing = Date.now();
for(const key in ex.clients)
{
if(key.startsWith("ws"))
{
ex.clients[key].connection.ping(); // ?data, mask, cb?
// ex.clients[key].ping(); // doesn't seem to do anything
}
}
}
I intercept the pong
s, but they look as arriving by server's own schedule, after the predefined interval. In other words, my ping
s either are not sent at all, or ignored for some reason, silently - there are no exceptions.
Probably my approach with "poking" the client object is incorrect, but it's just a result of digging into the source code and debugging, because I did not find any official info on how to do this.
Any suggestions on how to send "effective" ping
s (force the remote server to answer with pong
s) or measure websocket latency in another way?
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745123717a4612566.html
评论列表(0条)