Search Unity

Nat Target 0 not connected to Nat Facilitator

Discussion in 'Multiplayer' started by Korigoth, Dec 17, 2014.

  1. Korigoth

    Korigoth

    Joined:
    Jul 21, 2014
    Posts:
    105
    Hi everyone,

    i'm currently building a game in 2d... that i previously started in 3d.

    My 3D game work fine and my network is working as intended!

    but now that i started my 2 game in a new project
    i got this error each time i try to connect to my server....

    what can cause the probleme.....
    i have the same port of my 3d game and they dont run at the same time.... why does the 3d game work and my 2d game got a error of nat.????
     
  2. Korigoth

    Korigoth

    Joined:
    Jul 21, 2014
    Posts:
    105
    the worse part is ...... the GUI from unity 4.6 make it fail.....

    cause i tried with the GUI.Button fashion and it work perfect.... my player can connect to the server


    Working Code

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. namespace Assets.Scripts.Network
    4. {
    5.     public class NetworkManager : MonoBehaviour
    6.     {
    7.         public Transform[] SpawnPoints;
    8.         public GameObject PlayerPrefab;
    9.  
    10.         private string _currentMenu;
    11.  
    12.         private const float BtnW = 150;
    13.         private const float BtnH = 40;
    14.  
    15.         private HostData[] _hostData = null;
    16.  
    17.         private const string GameName = "Keep the Circles";
    18.         private const string RoomName = "Rocky Valley";
    19.         private const string TypeGame = "A capture the flag game";
    20.  
    21.         private const int MaxNbPlayer = 2;
    22.  
    23.         private const int ListenPort = 25001;
    24.  
    25.         void Start ()
    26.         {
    27.             _currentMenu = "Multiplayer";
    28.         }
    29.  
    30.         private void StartServer()
    31.         {
    32.             UnityEngine.Network.InitializeServer(MaxNbPlayer, ListenPort, !UnityEngine.Network.HavePublicAddress());
    33.  
    34.             // A decommenter si le server unity est down pour rouller le serveur en local.
    35.             //MasterServer.ipAddress = "127.0.0.1";
    36.             MasterServer.RegisterHost(GameName, RoomName, TypeGame);
    37.         }
    38.  
    39.         private void RefreshHostList()
    40.         {
    41.             MasterServer.RequestHostList(GameName);
    42.         }
    43.  
    44.         private void SpawnPlayer()
    45.         {
    46.             var player = (GameObject) UnityEngine.Network.Instantiate(PlayerPrefab, SpawnPoints[UnityEngine.Network.connections.Length].position, Quaternion.identity, 0);
    47.             player.networkView.RPC("SetColor", RPCMode.AllBuffered, new Vector3(UnityEngine.Network.connections.Length, 0, 0));
    48.         }
    49.  
    50.         void OnServerInitialized()
    51.         {
    52.             Debug.Log("Server Initialized!");
    53.             SpawnPlayer();
    54.         }
    55.  
    56.         void OnMasterServerEvent(MasterServerEvent mse)
    57.         {
    58.             if (mse == MasterServerEvent.RegistrationSucceeded)
    59.             {
    60.                 Debug.Log("Registered Server");
    61.             }
    62.             else if (mse == MasterServerEvent.HostListReceived)
    63.             {
    64.                 _hostData = MasterServer.PollHostList();
    65.             }
    66.         }
    67.  
    68.         void OnConnectedToServer()
    69.         {
    70.             SpawnPlayer();
    71.         }
    72.  
    73.         void OnGUI()
    74.         {
    75.             if (_currentMenu == "Main")
    76.                 Menu_Main();
    77.  
    78.             if (_currentMenu == "Multiplayer")
    79.                 Menu_Multiplayer();
    80.  
    81.         }
    82.  
    83.         void Menu_Main()
    84.         {
    85.  
    86.         }
    87.  
    88.         void Menu_Multiplayer()
    89.         {
    90.             if (!UnityEngine.Network.isClient && !UnityEngine.Network.isServer)
    91.             {
    92.                 if (GUI.Button(new Rect(50, 50, BtnW, BtnH), "Start Server"))
    93.                 {
    94.                     StartServer();
    95.                 }
    96.  
    97.                 if (GUI.Button(new Rect(50, 100, BtnW, BtnH), "Refresh"))
    98.                 {
    99.                     Debug.Log("Refreshing...");
    100.                     RefreshHostList();
    101.                 }
    102.  
    103.                 GUILayout.BeginArea(new Rect(Screen.width - 500, 0, 500, Screen.height), "Server List");
    104.                 GUILayout.Space(20);
    105.  
    106.                 foreach (HostData hostedGame in MasterServer.PollHostList())
    107.                 {
    108.                     GUILayout.BeginHorizontal("Box");
    109.                     GUILayout.Label(hostedGame.gameName);
    110.  
    111.                     if (GUILayout.Button("Connect"))
    112.                     {
    113.                         UnityEngine.Network.Connect(hostedGame);
    114.                     }
    115.  
    116.                     GUILayout.EndHorizontal();
    117.                 }
    118.  
    119.                 GUILayout.EndArea();
    120.             }
    121.         }
    122.  
    123.     }
    124. }







    Code That fail ??? and i dont understand what's wrong with it....
    my start server button = StartServer
    my connect button = RefreshHostList
    my Room button = ConnectToRoomEvent(roomName)

    everything work excep the RoomButton that give me the Nat error....


    Code (CSharp):
    1. using Assets.Scripts.GUI;
    2. using UnityEngine;
    3. using UnityEngine.UI;
    4.  
    5. namespace Assets.Scripts
    6. {
    7.     public class NetworkManager : MonoBehaviour
    8.     {
    9.         public Transform[] SpawnPoints;
    10.         public GameObject PlayerPrefab;
    11.  
    12.         private string _currentMenu;
    13.  
    14.         private const float BtnW = 150;
    15.         private const float BtnH = 40;
    16.  
    17.         private HostData[] _hostData = null;
    18.  
    19.         public Button RoomButton;
    20.         public Canvas Canvas;
    21.  
    22.         private const string GameName = "Keep the Circles";
    23.         private const string RoomName = "Rocky Valley";
    24.         private const string TypeGame = "A capture the flag game";
    25.  
    26.         private const int MaxNbPlayer = 2;
    27.  
    28.         private const int ListenPort = 25001;
    29.  
    30.         void Start()
    31.         {
    32.             _currentMenu = "Multiplayer";
    33.         }
    34.  
    35.         public void StartServer()
    36.         {
    37.             Network.InitializeServer(MaxNbPlayer, ListenPort, !Network.HavePublicAddress());
    38.  
    39.             // A decommenter si le server unity est down pour rouller le serveur en local.
    40.             //MasterServer.ipAddress = "127.0.0.1";
    41.             MasterServer.RegisterHost(GameName, RoomName, TypeGame);
    42.         }
    43.  
    44.         public void RefreshHostList()
    45.         {
    46.             MasterServer.RequestHostList(GameName);
    47.         }
    48.  
    49.         private void SpawnPlayer()
    50.         {
    51.             var player = (GameObject) Network.Instantiate(PlayerPrefab, SpawnPoints[Network.connections.Length].position, Quaternion.identity, 0);
    52.         }
    53.  
    54.         void OnServerInitialized()
    55.         {
    56.             Debug.Log("Server Initialized!");
    57.             SpawnPlayer();
    58.         }
    59.  
    60.         void OnMasterServerEvent(MasterServerEvent mse)
    61.         {
    62.             if (mse == MasterServerEvent.RegistrationSucceeded)
    63.             {
    64.                 Debug.Log("Registered Server");
    65.             }
    66.             else if (mse == MasterServerEvent.HostListReceived)
    67.             {
    68.                 _hostData = MasterServer.PollHostList();
    69.  
    70.                 for (int i = 0; i < _hostData.Length; i++)
    71.                 {
    72.                     var button = GuiHelper.CreateButton(RoomButton, Canvas, new Vector2(0.03f, 0.87f - (i * 0.20f)), new Vector2(0.23f, 0.94f - (i * 0.18f)));
    73.                     var text = button.GetComponentInChildren<Text>();
    74.                     text.text = _hostData[i].gameName;
    75.  
    76.                     var roomName = _hostData[i].gameName;
    77.                     button.onClick.AddListener(() => ConnectToRoomEvent(roomName));
    78.                 }
    79.             }
    80.         }
    81.  
    82.         private void ConnectToRoomEvent(string roomName)
    83.         {
    84.             Network.Connect(roomName);
    85.         }
    86.  
    87.         void OnConnectedToServer()
    88.         {
    89.             SpawnPlayer();
    90.         }
    91.     }
    92. }
    93.  
     
  3. Korigoth

    Korigoth

    Joined:
    Jul 21, 2014
    Posts:
    105
    plz i need help....

    my project cannot run ... with this problem....
     
  4. Korigoth

    Korigoth

    Joined:
    Jul 21, 2014
    Posts:
    105
    is it possible to get some help... i'm stuck with the new Unity GUI that doesn't let me connect to my server as host....