Network.Connect returns immediately then throws Exception?

So according to the docs - Network.Connect is supposed to return a NetworkConnectionError that denotes whether or not the connection happened. I figured I would check this returned value to display some info to the user if they weren’t able to connect for whatever reason. What seems to be happening is that Network.Connect returns immediately with a clean NetworkConnectionError (NoError) and after some time elapses (a timeout setting on the socket I’m guessing) Unity throws an Exception saying it couldn’t connect to such-and-such IP address.

Is this the way it’s supposed to work? I should mention that I’m connecting via LAN directly and not through a Master Server. Does that have something to do with it? The bummer is, I’m hooking Unity’s error handling in order to treat every Exception like an “assert” in the standalone build so I don’t want this Exception bubbling up to the user and causing my game to exit - and I really would rather not suppress displaying the error message based on the string contained in it (something I’ve unfortunately already had to do to some degree).

Thoughts?

Just giving this a bump.

Is the preferred method to use the MonoBehaviour “events” for connection success/failure? It seems odd for these methods to return values that apparently aren’t accurate.

Why not simply use the network callbacks ?
OnConnectedToServer
OnDisconnectedFromServer
OnFailedToConnect
OnNetworkInstantiate
OnPlayerConnected
OnPlayerDisconnected
OnSerializeNetworkView
OnServerInitialized
On the left side of this page :
http://docs.unity3d.com/Documentation/ScriptReference/Network.Connect.html

Indeed I could. I was looking to use the returned enum because the class that manages connections does not inherit from MonoBehaviour.

Curious why the documented functionality doesn’t appear to function as documented. :slight_smile:

EDIT: Here’s basically what I wanted to do.

public NetworkConnectionError Connect()
{
    return Network.Connect(ip, port);
}

public void Foo()
{
    NetworkConnectionError e = Connect();
    if (e == NetworkConnectionError.NoError)
        // go to lobby screen
    else
        // display some message to player that they can't connect
}

I have noticed the same issue. Furthermore, it seens that, when you call a MasterServer function and it triggers an OnFailedToConnectToMasterServer event (like, let’s say my own MasterServer is not running yet), Unity stops trying to comunicate to the MasterServer even if you call the MasterServer functions like RequestHostList() or RegisterHost(), and start the Master Server service.

I have tha same problem. RequestHostList and RegisterHost don’t work if the connection failed once. You have to restart the Game. Someone has a solution for this?

I already used Network.Disconnect(), but still the same problem.