I'm trying to make a system to ping a list of websocket servers, in order to check if they're online and have free slots. Using the following code, I can ping one server:
But how could I ping a list of servers? Because using the code above for an array of servers to ping won't work, I assume.
I need a system like this to make a correct list of servers the player can join in my game(The game downloads a .txt file with a list of servers, then the client pings all of them and list those who answered in under 5 seconds).
Code:
Somevariable = new WebSocket("ws://IP:port")
Somevariable.onopen=function(){
Somevariable.send("ping") //Sends the message "ping" after connecting
}
Somevariable.onmessage=function(message){
if(message==="online"){
//If the server answers with "online", the IP is added to an array that will be displayed afterwards
}
}
But how could I ping a list of servers? Because using the code above for an array of servers to ping won't work, I assume.
I need a system like this to make a correct list of servers the player can join in my game(The game downloads a .txt file with a list of servers, then the client pings all of them and list those who answered in under 5 seconds).