Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Need help Host Connection Fail

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

  1. Korigoth

    Korigoth

    Joined:
    Jul 21, 2014
    Posts:
    105
    Hi,

    I seriously need help....to see why i cannot connect to the masterserver as client...

    i always get the "NAT target 0 not connected to NAT facilitator 67.225.180.24:50005"

    here is my code

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. namespace Assets.Scripts.Manager
    4. {
    5.     public class NetworkManager : MonoBehaviour
    6.     {
    7.         public const string GameName = "Keep the circle";
    8.         public const string RoomName = "Room1";
    9.         public const string TypeGame = "Capture the flags";
    10.  
    11.         public const int ListenPort = 25000;
    12.         public const int NbPlayer = 5;
    13.  
    14.         public PlayerManager Player;
    15.  
    16.         public HostData[] _hostList;
    17.  
    18.         private bool _tryingToConnect = false;
    19.  
    20.         private MainMenuManager _mainMenuManager;
    21.  
    22.         public void StartServer(MainMenuManager mainMenuManager)
    23.         {
    24.             _mainMenuManager = mainMenuManager;
    25.             Network.InitializeServer(NbPlayer, ListenPort, !Network.HavePublicAddress());
    26.             MasterServer.RegisterHost(GameName, RoomName, TypeGame);
    27.             _mainMenuManager.DisableCanvas();
    28.         }
    29.  
    30.         public void ConnectToServer(MainMenuManager mainMenuManager)
    31.         {
    32.             _mainMenuManager = mainMenuManager;
    33.             MasterServer.RequestHostList(GameName);
    34.         }
    35.  
    36.         #region LifeCycle
    37.  
    38.         void Update()
    39.         {
    40.             if (_tryingToConnect)
    41.             {
    42.                 if (!Network.isClient && !Network.isServer)
    43.                 {
    44.                     Debug.Log(_hostList[0]);
    45.                     if (Network.Connect(_hostList[0].gameName) == NetworkConnectionError.ConnectionFailed)
    46.                     {
    47.                         Debug.Log("Erreur de connection");
    48.                     }
    49.  
    50.                     _tryingToConnect = false;
    51.                 }
    52.             }
    53.         }
    54.  
    55.         void OnServerInitialized()
    56.         {
    57.             Debug.Log("Server Initialized!");
    58.             var player = Network.Instantiate(Player, new Vector3(0, 3, 0), Quaternion.identity, 0) as PlayerManager;
    59.             player.networkView.RPC("SetColor", RPCMode.AllBuffered, new Vector3(255, 0, 0));
    60.         }
    61.  
    62.         void OnConnectedToServer()
    63.         {
    64.             Debug.Log("Connection Initialized!");
    65.             var player = Network.Instantiate(Player, new Vector3(1, 1, 0), Quaternion.identity, 0) as PlayerManager;
    66.             player.networkView.RPC("SetColor", RPCMode.AllBuffered, new Vector3(0, 255, 0));
    67.         }
    68.  
    69.         void OnMasterServerEvent(MasterServerEvent mse)
    70.         {
    71.             if (mse == MasterServerEvent.RegistrationSucceeded)
    72.             {
    73.                 Debug.Log("Registered Server");
    74.             }
    75.             else if (mse == MasterServerEvent.HostListReceived)
    76.             {
    77.                 _hostList = MasterServer.PollHostList();
    78.                
    79.                 if (!Network.isClient && !Network.isServer)
    80.                 {                  
    81.                     if (_hostList.Length > 0)
    82.                     {
    83.                         _tryingToConnect = true;                  
    84.                     }
    85.                     else
    86.                     {
    87.                         Debug.Log("Nothing Found");
    88.                     }
    89.                 }
    90.  
    91.             }
    92.         }
    93.  
    94.         #endregion
    95.     }
    96. }

    plz i need ur help
     
  2. Korigoth

    Korigoth

    Joined:
    Jul 21, 2014
    Posts:
    105
    i found that

    Code (CSharp):
    1.             else if (mse == MasterServerEvent.HostListReceived)
    2.             {
    3.                 if (MasterServer.PollHostList().Length > 0) // is always 0 Length ??? why
    4.                 {
    5.                     _hostList = MasterServer.PollHostList();
    6.                     _tryingToConnect = true;  
    7.                 }
    8.             }
    9.