Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Network Connection Test Question

Discussion in 'Multiplayer' started by ProtonOne, Oct 5, 2008.

  1. ProtonOne

    ProtonOne

    Joined:
    Mar 8, 2008
    Posts:
    406
    What does this mean:

    Code (csharp):
    1. ConnectionTesterStatus.PublicIPNoServerStarted
    2.  
    3. [b]Description[/b]
    4.  
    5. Public IP address detected but server is not initialized and no port is listening.
    http://unity3d.com/support/document...tionTesterStatus.PublicIPNoServerStarted.html


    I gave one of my computers a public IP and turned off the windows firewall, then ran the example network project:
    http://protonfoundry.com/NetworkTest

    At first it says:
    Why do I need to start a server to test a computer with a public IP but not one with a private IP?

    Then if I start the server and press retest connection, about 10 seconds later it says:
    Which is the ConnectionTesterStatus.Error case. Why is it doing that?

    For my game, I am using the connection tester to try and fill in 5 static variables:
    Code (csharp):
    1. static var doneTesting : boolean = false;
    2.  
    3. // Public Network Test Variables
    4. static var canBeServer : boolean = false;
    5. static var serverMustUseNat : boolean = false;
    6. static var clientCanUseNat : boolean = false;
    7. static var natCapable : ConnectionTesterStatus = ConnectionTesterStatus.Undetermined;
    8.  
    9.  
    10. // Private Variables
    11. private var filterNATHosts = false;
    12. private var probingPublicIP = false;
    13. private var timer : float = 0.0;
    14.  
    15. private var testMessage = "Undetermined NAT capabilities";
    16.  
    17. function Awake ()
    18. {  
    19.     // Start connection test
    20.     natCapable = Network.TestConnection();
    21.    
    22.     DontDestroyOnLoad (this);
    23. }
    24.  
    25. function Update() {
    26.     // If test is undetermined, keep running
    27.     if (!doneTesting) {
    28.         var oldMessage : String = testMessage;
    29.         TestConnection();
    30.         if( oldMessage != testMessage ){
    31.             Console.Log( testMessage );
    32.         }
    33.     }
    34.     else{
    35.         this.enabled = false;
    36.     }
    37. }
    38.  
    39. function TestConnection() {
    40.     // Start/Poll the connection test, report the results in a label and react to the results accordingly
    41.     natCapable = Network.TestConnection();
    42.     switch (natCapable) {
    43.         case ConnectionTesterStatus.Error:
    44.             testMessage = "Problem determining NAT capabilities";
    45.             doneTesting = true;
    46.            
    47.             // Set Public variables
    48.             canBeServer = false;
    49.             serverMustUseNat = Network.HavePublicAddress();
    50.             clientCanUseNat = true;
    51.             break;
    52.            
    53.         case ConnectionTesterStatus.Undetermined:
    54.             testMessage = "Undetermined NAT capabilities";
    55.             canBeServer = false;
    56.             serverMustUseNat = Network.HavePublicAddress();
    57.             clientCanUseNat = true;
    58.             doneTesting = false;
    59.             break;
    60.            
    61.         case ConnectionTesterStatus.PrivateIPNoNATPunchthrough:
    62.             testMessage = "Cannot do NAT punchthrough, filtering NAT enabled hosts for client connections, local LAN games only.";
    63.             filterNATHosts = true;
    64.             Network.useNat = true;
    65.             doneTesting = true;
    66.            
    67.             // Set Public variables
    68.             canBeServer = false;
    69.             serverMustUseNat = false;
    70.             clientCanUseNat = false;
    71.             break;
    72.            
    73.         case ConnectionTesterStatus.PrivateIPHasNATPunchThrough:
    74.             if (probingPublicIP)
    75.                 testMessage = "Non-connectable public IP address (port blocked), NAT punchthrough can circumvent the firewall.";
    76.             else
    77.                 testMessage = "NAT punchthrough capable. Enabling NAT punchthrough functionality.";
    78.             // NAT functionality is enabled in case a server is started,
    79.             // clients should enable this based on if the host requires it
    80.             Network.useNat = true;
    81.             doneTesting = true;
    82.            
    83.             // Set Public variables
    84.             canBeServer = true;
    85.             serverMustUseNat = true;
    86.             clientCanUseNat = true;
    87.             break;
    88.            
    89.         case ConnectionTesterStatus.PublicIPIsConnectable:
    90.             testMessage = "Directly connectable public IP address.";
    91.             Network.useNat = false;
    92.             doneTesting = true;
    93.            
    94.             // Set Public variables
    95.             canBeServer = true;
    96.             serverMustUseNat = false;
    97.             clientCanUseNat = true;
    98.             break;
    99.            
    100.         // This case is a bit special as we now need to check if we can
    101.         // cicrumvent the blocking by using NAT punchthrough
    102.         case ConnectionTesterStatus.PublicIPPortBlocked:
    103.             testMessage = "Non-connectble public IP address (port blocked), running a server is impossible.";
    104.             Network.useNat = false;
    105.             // If no NAT punchthrough test has been performed on this public IP, force a test
    106.             if (!probingPublicIP)
    107.             {
    108.                 Debug.Log("Testing if firewall can be circumnvented");
    109.                 natCapable = Network.TestConnectionNAT();
    110.                 probingPublicIP = true;
    111.                 timer = Time.time + 10;
    112.             }
    113.             // NAT punchthrough test was performed but we still get blocked
    114.             else if (Time.time > timer)
    115.             {
    116.                 probingPublicIP = false;        // reset
    117.                 Network.useNat = true;
    118.                 doneTesting = true;
    119.                
    120.                 // Set Public variables
    121.                 canBeServer = false;
    122.                 serverMustUseNat = false;
    123.                 clientCanUseNat = true;
    124.             }
    125.             break;
    126.         case ConnectionTesterStatus.PublicIPNoServerStarted:
    127.             testMessage = "Public IP address but server not initialized, it must be started to check server accessibility. Restart connection test when ready.";
    128.             break;
    129.         default:
    130.             testMessage = "Error in test routine, got " + natCapable;
    131.     }
    132.     //Debug.Log(natCapable + " " + probingPublicIP + " " + doneTesting);
    133. }
    I just realized this never sets isDone=true for a computer with a public IP when the result is PublicIPNoServerStarted.

    Perhaps I am misunderstanding how this connection tester works? Any ideas or advice, are appreaciated.