Check if Server exists at IP

I’ve read over the documentation here but am not quite sure how to catch the errors. I set up an example where I attempt to connect to my own computer where a server is not running, and Debug.Log(Network.Connect(foo, bar)) prints “No error.” After a short pause, Unity prints the line “The connection request to foo:bar failed. Are you sure the server can be connected to?” I get the same result when using random IP addresses.

So my question is, how do I check if a server is running at a given IP?

It’s a good idea to read/search the documentation before asking questions :slight_smile:

OnFailedToConnect: Called on the client when a connection attempt fails for some reason.

OnConnectedToServer: Called on the client when you have successfully connected to a server.

And so on…

You cannot use a try/catch statement to do this. Instead use:

void OnFailedToConnect(NetworkConnectionError error) {
    Debug.Log("Could not connect to server: " + error);
}

Additionally, it appears that there is no way to check if a server is running without simply trying to connect to it.