Search Unity

Network.TestConnection() crashes the app on lan?

Discussion in 'Multiplayer' started by Ethan, Dec 9, 2008.

  1. Ethan

    Ethan

    Joined:
    Jan 2, 2008
    Posts:
    501
    Hi all,

    just as i wrote in the title, my app crashes if i am in a local network without access to the internet when i use Network.TestConnection().

    my game starts normaly, i set the ip and port for the masterserver in Start(), but when i click on my gui for the internet server browser (which runs TestConnection - see code down the page), it crashes the program if i have no internet available.
    if i plug out the lan cable completely, it doesnt crash - just if there is LAN only with no internet.
    and i dont get any informations in output_log.txt
    in mac i got sth like (but i dont know what this says):

    some code:

    Code (csharp):
    1. function Update()
    2. {
    3.     if (!doneTesting  curGuiWindow == eActiveGuiWindow.serverBrowser )
    4.     {
    5.         TestConnection();
    6.     }
    7.  
    8. }
    9.  
    10. // this function is out of the networking demo!
    11. function TestConnection() {
    12.     // Start/Poll the connection test, report the results in a label and react to the results accordingly
    13.     natCapable = Network.TestConnection();
    14.     switch (natCapable) {
    15.         case ConnectionTesterStatus.Error:
    16.             testMessage = "Problem determining NAT capabilities";
    17.             doneTesting = true;
    18.             break;
    19.            
    20.         case ConnectionTesterStatus.Undetermined:
    21.             testMessage = "Undetermined NAT capabilities";
    22.             doneTesting = false;
    23.             break;
    24.            
    25.         case ConnectionTesterStatus.PrivateIPNoNATPunchthrough:
    26.             testMessage = "Cannot do NAT punchthrough, filtering NAT enabled hosts for client connections, local LAN games only.";
    27.             filterNATHosts = true;
    28.             Network.useNat = true;
    29.             doneTesting = true;
    30.             break;
    31.            
    32.         case ConnectionTesterStatus.PrivateIPHasNATPunchThrough:
    33.             if (probingPublicIP)
    34.                 testMessage = "Non-connectable public IP address (port "+ serverPort +" blocked), NAT punchthrough can circumvent the firewall.";
    35.             else
    36.                 testMessage = "NAT punchthrough capable. Enabling NAT punchthrough functionality.";
    37.             // NAT functionality is enabled in case a server is started,
    38.             // clients should enable this based on if the host requires it
    39.             Network.useNat = true;
    40.             doneTesting = true;
    41.             break;
    42.            
    43.         case ConnectionTesterStatus.PublicIPIsConnectable:
    44.             testMessage = "Directly connectable public IP address.";
    45.             Network.useNat = false;
    46.             doneTesting = true;
    47.             break;
    48.            
    49.         // This case is a bit special as we now need to check if we can
    50.         // cicrumvent the blocking by using NAT punchthrough
    51.         case ConnectionTesterStatus.PublicIPPortBlocked:
    52.             testMessage = "Non-connectble public IP address (port " + serverPort +" blocked), running a server is impossible.";
    53.             Network.useNat = false;
    54.             // If no NAT punchthrough test has been performed on this public IP, force a test
    55.             if (!probingPublicIP)
    56.             {
    57.                 Debug.Log("Testing if firewall can be circumnvented");
    58.                 natCapable = Network.TestConnectionNAT();
    59.                 probingPublicIP = true;
    60.                 timer = Time.time + 10;
    61.             }
    62.             // NAT punchthrough test was performed but we still get blocked
    63.             else if (Time.time > timer)
    64.             {
    65.                 probingPublicIP = false;        // reset
    66.                 Network.useNat = true;
    67.                 doneTesting = true;
    68.             }
    69.             break;
    70.         case ConnectionTesterStatus.PublicIPNoServerStarted:
    71.             testMessage = "Public IP address but server not initialized, it must be started to check server accessibility. Restart connection test when ready.";
    72.             break;
    73.         default:
    74.             testMessage = "Error in test routine, got " + natCapable;
    75.     }
    76.     Debug.Log(natCapable + " " + probingPublicIP + " " + doneTesting);
    77. }
    78.  
    additional information:
    i am using unity pro 2.1.0 licence,
    same bug/behaviour/crash on windows mac binaries in editor

    EDIT / PS:
    it crashes also if i start a server on LAN without internet
    code:

    Code (csharp):
    1. Network.useNat = !Network.HavePublicAddress();
    2. Network.InitializeServer(15, serverPort);
    3. MasterServer.RegisterHost(gameName, serverName, comments);