- Home /
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?
Answer by No_Username_Found · May 30, 2014 at 12:54 AM
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.
http://docs.unity3d.com/ScriptReference/Network.OnFailedToConnect.html
Answer by Benproductions1 · May 17, 2014 at 08:21 AM
It's a good idea to read/search the documentation before asking questions :)
https://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.html
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...
Your answer
Follow this Question
Related Questions
Question about UNET 0 Answers
Unity networking tutorial? 6 Answers
smartfoxserver keeps me logged in after exiting game 1 Answer
Unity Master Server - Good to use? 1 Answer
Error: The requested address is not valid in its context. 1 Answer