Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
264 views
in Technique[技术] by (71.8m points)

javascript - 如何使用socket.io一次ping通多个IP(How to ping multiple ip one after other using socket.io)

I have some URL(number of URL can vary) whom i want to ping using socket.io one after the other.Means receiving ping of first url, then request of second.

(我有一些URL(URL的数量可以变化),我想一个接一个地使用socket.io进行ping。这意味着先接收第一个url的ping,然后接收第二个url的ping。)

var okPing=[];
for(let i=0;i<urls.length;i++){
    let temp_socket=io.connect(urls[i]);
    checkPing(temp_socket);
    checkPong(temp_socket);//How to wait for pong here?It will not get response in the same order
    temp_soc.disconnect();
    temp_soc.close();
    temp_soc=null;
}
function checkPing(socket){
    startPingTime = Date.now();
    socket.emit('pingcheck');
}
function checkPong(socket){
    socket.on('pongcheck');
}

What to do to get the response in order of execution?

(如何执行才能获得响应?)

  ask by JustStarted translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...