Search Unity

My Master Server and your Network.TestConnection

Discussion in 'Multiplayer' started by will_w, Apr 27, 2009.

  1. will_w

    will_w

    Joined:
    Feb 20, 2008
    Posts:
    56
    My master server was having no problems. Rock solid for days on end without a restart (running on an old dualg5 xserve). Then I ran the unity Networking demo and some weird stuff has started.

    Most importantly:

    Connection Tester reports NAT target 72.52.207.14:10735 not connected to NAT facilitator xxx.xxx.xxx.xxx:xxxxx.

    (the x are my ip and port)

    I have tried restarting everything. Disabling firewalls (even though it was working fine). Clients connect, and the MS server log shows the connections and messages fine. I see no errors in the logs.

    The only error seems to be coming from the connection tester.

    Is there someplace I'm supposed to set something. I have the server on port 11067 and the facilitator on 11068. My scripts were using this and work fine if I manually set the NAT. But this connection tester thingy has me a little bummed.

    There are other weird things happening after I ran the networking demo, is it possible that there are some pro-only assets in there that have corrupted my unity install or something? For example the first time I ran the demo - all fine. All parts worked. Then I literaly fixed one typo in one of the comments that was bugging me and it stopped working. I trashed the demo. Unstuffed a new one. Opened it and got like 10 different errors that hadn't been there the first time.

    Have now wasted about 40 work hours trying to get my game that was working fine 3 days ago to play again.

    What's gotten corrupted? I only have indie, but if this is what using indie with a demo does then they really gotta let people know!!

    Any suggestions?
     
  2. MikeHergaarden

    MikeHergaarden

    Joined:
    Mar 9, 2008
    Posts:
    1,027
    Checked the logs of both your masterserver AND the connectiontester application?

    Make sure they are connected properly.
     
  3. will_w

    will_w

    Joined:
    Feb 20, 2008
    Posts:
    56
    Thanks for the tip but yep. They are communicating fine. I've actually re-done the connection stuff in my scripts and removed the offending code and everything works fine. Remote, and NAT enabled, and local and everything works fine - my client games connect automatically to my server game from anywhere.

    I have not had the time to add the connectionTester stuff back in. I'll update when (read if) I do.
     
  4. will_w

    will_w

    Joined:
    Feb 20, 2008
    Posts:
    56
    I have come to the decision that someplace in the connection test is a hard coded IP address for the Unity NAT facilitator.

    This is very frustrating:

    Connection Tester reports NAT target 72.52.207.14:10735 not connected to NAT facilitator 24.106.214.29:11068.

    I get that error even if the game is running fine, the server using NAT or not.

    Also, there are two versions of the test
    Connection script floating around - the one in the networking demo, and the one from the docs.

    I am pretty damn frustrated at this point. I keep getting my game working, then lose a day trying to use Unity's demos and code. I know I'm no wiz - but all the more reason I need to be able to count on Unity not releasing buggy software. I know the MasterServer is still in beta, but is the testConnection and testConnectionNAT still in beta?

    Now I will go back for the 3rd time - remove all the testConnection functionality and try to move forward on the project.

    And finally - I know its "soooo 90's" to have a search function, but wtf - no search in the manual and reference?

    C'mon Unity - this stuff is basic.
     
  5. will_w

    will_w

    Joined:
    Feb 20, 2008
    Posts:
    56
     
  6. will_w

    will_w

    Joined:
    Feb 20, 2008
    Posts:
    56
    Should these values be set to the local machine, the server machine, the master server machine or none of the above?

    The docs are useless.
     
  7. MikeHergaarden

    MikeHergaarden

    Joined:
    Mar 9, 2008
    Posts:
    1,027
    I host the masterserver&connectiontester on one server. If you have the same setup, then your unity side could should be:

    Code (csharp):
    1. var masterserverIP ="1.1.1.1";
    2.  
    3. Network.natFacilitatorIP = masterserverIP;
    4. Network.natFacilitatorPort = 44444;
    5. MasterServer.ipAddress = masterserverIP;
    6. MasterServer.port = 33333;
    7. Network.connectionTesterIP = masterserverIP;
    8. Network.connectionTesterPort = 55555;
    That's all code there is to it. Do note to change the masterserverIP, and note that I changed the default ports.

    Then...you need to run both the connectiontester, and the masterserver on your server. Read both logs to check if they connect to eachother properly.
    I believe there were indeed some hardcoded Unity3D server IP's..even though some setting can also be given via the command line. To be sure you get it working you can probably try to hardcode your servers IP (or 127.0.0.1).
     
  8. will_w

    will_w

    Joined:
    Feb 20, 2008
    Posts:
    56
    Another great answer from Leepo. If I wasn't a starving artist I'd hire you :)

    In fact - that is exactly the setup I have after some trial and error. Everything does indeed talk to each other. But I am still getting those weird errors when I use ConnectionTester.

    Good news though!
    If I just use this to establish the client connection, everything works fine:

    Network.useNat = Network.HavePublicAddress();

    Its weird that it works, cause notice that I've removed the ! , so basically this code means if the machine has a public IP its using NAT, which seems very bassackwards to me. And this line does affect the operation - if I put the exclamation mark back in it fails to connect. The Master Server runs with a static IP, and it is behind my firewall.

    I'm not complaining however - it works!

    I've tested it on machines behind my firewall, public, remote and local.

    I can run my game from any machine on my network to any machine on my network. They all have Private IPs like 192.168.2.10 and connect to the internet using NAT on a different IP than the Master is on, so they have to go out and come back in to get to the Master, and everything is fine.

    And I have had no probs having external clients connect from other states and other countries to any machine on my network.

    And I have had no probs connecting from my internal to those same outside machines as a client.

    I can run my game server on the same machine as the Master Server if I want and that works fine.

    Basically, as long as I don't use the connectionTester everything works.

    At this point I'm not really sure what I need the connectionTester for. :)

    I guess at some point maybe I'll find something in Unity that requires it and I'll have to work it back in, but I have about 87 other weird Unity bugs I'm trying to work through right now.

    Thanks for your help and response though. You really have been a lone beacon of help for me on these issues.
     
  9. MikeHergaarden

    MikeHergaarden

    Joined:
    Mar 9, 2008
    Posts:
    1,027
    Haha alright, I'm happy that you got it working fairly well for now.

    I have to agree that the whole NAT stuff is pretty messy. I also never even got NAT punchtrough to work for my router (got to open the ports, and external clients need to disconnect nat when connecting to me).
     
  10. will_w

    will_w

    Joined:
    Feb 20, 2008
    Posts:
    56
    Here's my semi-cannibalized script that I use. the only thing that might not be obvious is the resetMSIP() function - that's the function that is composed of exactly what you put above to reset the MasterServer connection info (with my MS info of course). oh and that serverControl var is to let me display or not display this from the OnGUI. ie.

    Code (csharp):
    1. function OnGUI() {
    2.      if (serverControl){
    3.            ResetMSIP();
    4.            ServerControlRect = GUILayout.Window ( 1 , ServerControlRect , ServerControlWindow , "Server Controls");
    5.       }
    6. }

    Perhaps this will help you. I'd like to return the favor. And sorry for the formatting, I'm spoiled by my nice wide monitor. I no longer code for reading 80 characters wide :)

    Code (csharp):
    1. function ServerControlWindow (id : int) {
    2.  
    3.     hideTest = GUILayout.Toggle(hideTest, "Hide test info");
    4.     if (!hideTest) {
    5.         GUILayout.Label(testMessage);
    6.         if (GUILayout.Button ("Retest connection")){
    7.             Debug.Log("Redoing connection test");
    8.             probingPublicIP = false;
    9.             doneTesting = false;
    10.             natCapable = Network.TestConnection(true);
    11.         }
    12.     }
    13.  
    14.     GUILayout.BeginHorizontal();
    15.         GUILayout.Space(10);               
    16.         // Refresh hosts
    17.         if (GUILayout.Button ("Refresh available Servers") || Time.realtimeSinceStartup > lastHostListRequest + hostListRefreshTimeout){
    18.             MasterServer.RequestHostList(gameName);
    19.             lastHostListRequest = Time.realtimeSinceStartup;
    20.         }      
    21.         if (Network.peerType == NetworkPeerType.Disconnected){         
    22.             GUILayout.Space(10);           
    23.             // Start a new server
    24.             if (GUILayout.Button ("Start Non-Dedicated Server")){
    25.                 Network.useNat = !Network.HavePublicAddress();
    26.                 Network.InitializeServer(32, serverListenPort);
    27.                 MasterServer.RegisterHost(gameName, mapName, serverComment);
    28.             }          
    29.             if (GUILayout.Button("Start Dedicated Server")) {
    30.                 // Use NAT punchthrough if no public IP present
    31.                 Network.useNat = !Network.HavePublicAddress();
    32.                 MasterServer.dedicatedServer = true;
    33.                 Network.InitializeServer(32, serverListenPort);
    34.                 MasterServer.RegisterHost(gameName, mapName, serverComment);
    35.             }
    36.         }          
    37.         GUILayout.FlexibleSpace(); 
    38.     GUILayout.EndHorizontal();
    39.     GUILayout.Space(5);
    40.  
    41.     ResetMSIP();
    42.  
    43.     var data : HostData[] = MasterServer.PollHostList();
    44.     for (var element in data){
    45.         GUILayout.BeginVertical();
    46.             // Do not display NAT enabled games if we cannot do NAT punchthrough
    47.             if ( !(filterNATHosts  element.useNat) ){  
    48.                 GUILayout.BeginHorizontal();   
    49.                     var name = element.gameName + " " + element.connectedPlayers + " / " + element.playerLimit;
    50.                     GUILayout.Label(name); 
    51.                     GUILayout.Space(5);
    52.                     var hostInfo;
    53.                     hostInfo = "[";
    54.                     for (var host in element.ip){                  
    55.                         hostInfo = hostInfo + host + ":" + element.port + " ";
    56.                         hostIP = host;
    57.                     }
    58.                     hostInfo = hostInfo + "]";
    59.                     GUILayout.Label(hostInfo); 
    60.                     GUILayout.Space(5);
    61.                     GUILayout.Label(element.comment);
    62.                     GUILayout.Space(5);
    63.                     GUILayout.FlexibleSpace();
    64.                 GUILayout.EndHorizontal();
    65.                 GUILayout.BeginHorizontal();                   
    66.                     playerIP = player.ipAddress;
    67.                     // Debug.Log("Element IP: "+hostIP+"  Player IP: "+playerIP);          
    68.                     if (hostIP != playerIP){
    69.                        
    70.                         // Connect to a Server
    71.                                    
    72.                         if (GUILayout.Button("Connect")){
    73.                            
    74.                             serverControl = false;
    75.                            
    76.                             // Enable NAT functionality based on what the host is configured to do
    77.                             Network.useNat = Network.HavePublicAddress();
    78.                            
    79.                             Debug.Log("Have Public Address = "+Network.HavePublicAddress());
    80.                            
    81.                             if (Network.useNat) Debug.Log("Using NAT to connect");
    82.                             else Debug.Log("Connecting directly to host");
    83.                                
    84.                             Network.Connect(element.ip, element.port);         
    85.                         }
    86.                     }  
    87.                     else {             
    88.                         // List all the games
    89.                         for (var level in supportedNetworkLevels){
    90.                             if (GUILayout.Button(level)){
    91.                                
    92.                                 // Connect to an individual Level
    93.                                 serverControl = false;
    94.                                
    95.                                 // Make sure no old RPC calls are buffered and then send load level command
    96.                                 Network.RemoveRPCsInGroup(0);
    97.                                 Network.RemoveRPCsInGroup(1);
    98.                                 // Load level with incremented level prefix (for view IDs)
    99.                                 networkView.RPC( "LoadLevel", RPCMode.AllBuffered, level, lastLevelPrefix + 1);
    100.                             }
    101.                         }
    102.                     GUILayout.FlexibleSpace();
    103.                     }
    104.                 GUILayout.EndHorizontal();                 
    105.             }
    106.             else { 
    107.                 if (GUILayout.Button ("Disconnect")){
    108.                     Network.Disconnect();
    109.                     MasterServer.UnregisterHost();
    110.                 }      
    111.                 GUILayout.FlexibleSpace();
    112.             }  
    113.         GUILayout.EndVertical();           
    114.     }
    115.     GUI.DragWindow (Rect (0,0,1000,1000));
    116. }
    117.