Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Resolved Server is not Reachable/Visible

Discussion in 'Netcode for GameObjects' started by Killzonetheone, May 19, 2024.

  1. Killzonetheone

    Killzonetheone

    Joined:
    May 4, 2024
    Posts:
    6
    I have some Problems with Netcode and Serverbuild

    I build the Server Project and Put in on a Server. All Port and Adresses are open and fine. But if i start the applikation the Server does not Listen to the Port. I hardcoded the Ip but nothink works

    Unity Version : 2022.3.27f1
    Netcode for GameObjects Version: 1.9.1

    In local Network all works fine. Server Starts and Client Connect. But not on Internet

    Servercode
    Code (CSharp):
    1.  #region #####PROPERTYS#####
    2. private string IpAdress { get; set; } ;
    3. private ushort Port { get; set; } = 27012;
    4. private string ListenAdress { get; set; } = "0.0.0.0";
    5.  
    6. #endregion #####PROPERTYS#####
    7.  
    8. #region #####CONSTRUCTOR#####
    9. #endregion #####CONSTRUCTOR#####
    10.  
    11. #region #####UNITY#####
    12.  
    13. //private void OnEnable()
    14. //{
    15. //    UnityTransport transport = gameObject.GetComponent<UnityTransport>();
    16. //    transport.SetConnectionData(IpAdress, Port, ListenAdress);
    17. //    NetworkConfig.NetworkTransport = transport;
    18.  
    19. //    OnServerStarted += ServerManager_OnServerStarted;
    20. //    OnClientConnectedCallback += ServerManager_OnClientConnectedCallback;
    21. //    OnClientDisconnectCallback += ServerManager_OnClientDisconnectCallback;
    22.  
    23. //    StartServer();
    24. //}
    25.  
    26. // Start is called before the first frame update
    27. void Start()
    28. {
    29.      IpAdress = GetLocalIPAddress();
    30.  
    31.      UnityTransport transport = gameObject.GetComponent<UnityTransport>();
    32.      transport.SetConnectionData(IpAdress, Port, ListenAdress);
    33.      NetworkConfig.NetworkTransport = transport;
    34.  
    35.      OnServerStarted += ServerManager_OnServerStarted;
    36.      OnClientConnectedCallback += ServerManager_OnClientConnectedCallback;
    37.      OnClientDisconnectCallback += ServerManager_OnClientDisconnectCallback;
    38.  
    39.      StartServer();
    40. }
    41.  
    42. // Update is called once per frame
    43. void Update()
    44. {
    45.      if (Console.ReadLine() == "Exit")
    46.      {
    47.          Debug.Log("Server gestoppt");
    48.          Application.Quit();
    49.      }
    50. }
    51.  
    52. #endregion #####UNITY#####
    53.  
    54. #region #####FUNKTIONS#####
    55.  
    56. private void ServerManager_OnClientDisconnectCallback(ulong obj)
    57. {
    58.      Console.WriteLine("Client Disconnectet");
    59.      //Debug.Log("Client Disconnectet");
    60. }
    61.  
    62. private void ServerManager_OnClientConnectedCallback(ulong obj)
    63. {
    64.      Console.WriteLine("Client Connectet");
    65.      //Debug.Log("Client Connectet");
    66. }
    67.  
    68. private void ServerManager_OnServerStarted()
    69. {
    70.      Console.WriteLine("Server listening for any Actions");
    71.      //Debug.Log("Server listening for any Actions");
    72. }
    73.  
    74. public string GetLocalIPAddress()
    75. {
    76.      using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, 0))
    77.      {
    78.          socket.Connect("8.8.8.8", Port);
    79.          IPEndPoint endPoint = socket.LocalEndPoint as IPEndPoint;
    80.          Console.WriteLine("Endpoint : " + endPoint.Address.ToString());
    81.          return endPoint.Address.ToString();
    82.      }
    83. }
    84.  
    85. #endregion #####FUNKTIONS#####
    View attachment 1416474

    What did i wrong ?
     
  2. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    2,163
    probably because your local Ip is say 10.x.x.x or 172.x.x.x and those are not routable on the internet..

    so my IP could be 10.10.10.1 and this gives you nothing, but its the only IP my pc knows.
     
  3. Killzonetheone

    Killzonetheone

    Joined:
    May 4, 2024
    Posts:
    6
    In the Ip Adress i Put in the ServerIP Adress but nothing happend
     
  4. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    2,163
    what exactly is not connecting? I dont see why google dns servers would be listening on port 27012, which is what 8.8.8.8 is... so..

    Either way your code returned a local IP not an internet IP, so, tbh you can listen all you like but the IP you give out has to be that of the router which must know to forward it on.. OR you use a relay in which case you dont need any of that shenanigans
     
  5. Killzonetheone

    Killzonetheone

    Joined:
    May 4, 2024
    Posts:
    6
    I think that was my misstake. I search for result to fix it and the 8.8.8.8 is a misstake.

    Code (CSharp):
    1. public class ServerManager : NetworkManager
    2. {
    3.     #region #####PROPERTYS#####
    4.     private string IpAdress { get; set; }
    5.     private ushort Port { get; set; } = 27012;
    6.     private string ListenAdress { get; set; } = "0.0.0.0";
    7.  
    8.     #endregion #####PROPERTYS#####
    9.  
    10.     #region #####CONSTRUCTOR#####
    11.     #endregion #####CONSTRUCTOR#####
    12.  
    13.     #region #####UNITY#####
    14.  
    15.     //private void OnEnable()
    16.     //{
    17.     //    UnityTransport transport = gameObject.GetComponent<UnityTransport>();
    18.     //    transport.SetConnectionData(IpAdress, Port, ListenAdress);
    19.     //    NetworkConfig.NetworkTransport = transport;
    20.  
    21.     //    OnServerStarted += ServerManager_OnServerStarted;
    22.     //    OnClientConnectedCallback += ServerManager_OnClientConnectedCallback;
    23.     //    OnClientDisconnectCallback += ServerManager_OnClientDisconnectCallback;
    24.  
    25.     //    StartServer();
    26.     //}
    27.  
    28.     // Start is called before the first frame update
    29.     void Start()
    30.     {
    31.         IpAdress = "0.0.0.0";//GetLocalIPAddress();
    32.  
    33.         UnityTransport transport = gameObject.GetComponent<UnityTransport>();
    34.         transport.SetConnectionData(IpAdress, Port,ListenAdress);
    35.         NetworkConfig.NetworkTransport = transport;
    36.  
    37.         OnServerStarted += ServerManager_OnServerStarted;
    38.         OnClientConnectedCallback += ServerManager_OnClientConnectedCallback;
    39.         OnClientDisconnectCallback += ServerManager_OnClientDisconnectCallback;
    40.  
    41.         StartServer();
    42.     }
    43.  
    44.     // Update is called once per frame
    45.     void Update()
    46.     {
    47.         if (Console.ReadLine() == "Exit")
    48.         {
    49.             Debug.Log("Server gestoppt");
    50.             Application.Quit();
    51.         }
    52.     }
    53.  
    54.     #endregion #####UNITY#####
    55.  
    56.     #region #####FUNKTIONS#####
    57.  
    58.     private void ServerManager_OnClientDisconnectCallback(ulong obj)
    59.     {
    60.         Console.WriteLine("Client Disconnectet");
    61.         //Debug.Log("Client Disconnectet");
    62.     }
    63.  
    64.     private void ServerManager_OnClientConnectedCallback(ulong obj)
    65.     {
    66.         Console.WriteLine("Client Connectet");
    67.         //Debug.Log("Client Connectet");
    68.     }
    69.  
    70.     private void ServerManager_OnServerStarted()
    71.     {
    72.         Console.WriteLine("Server listening for any Actions");
    73.         //Debug.Log("Server listening for any Actions");
    74.     }
    75.  
    76.     //public string GetLocalIPAddress()
    77.     //{
    78.     //    using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, 0))
    79.     //    {
    80.     //        socket.Connect("212.227.189.98", Port);
    81.     //        IPEndPoint endPoint = socket.LocalEndPoint as IPEndPoint;
    82.     //        Console.WriteLine("Endpoint : " + endPoint.Address.ToString());
    83.     //        return endPoint.Address.ToString();
    84.     //    }
    85.     //}
    86.  
    87.     #endregion #####FUNKTIONS#####
    88. }
    89.  
    i chaged my code but the Server is not Listen to his adress and port.
    I dont kow how to fix it.
    I have an Public Ip Adress and Port on the Server. But i dont know what i must parse in the connection Parameter so that the Server is Visible in Linux View where i can see which ports are listen.
    Where the ip adress 0.0.0.0 is , there i put my server adress in
     
    Last edited: May 19, 2024
  6. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    2,163
    so stop just pasting other peoples code and understand the code you have

    0.0.0.0 listens on all the ports the server has - that isnt necessarily wrong.. what is more than likely wrong is either the assumption that that port can be got to from the internet, that there are no firewalls, or the IP you are entering on the clients is non routable (see above) ...


    Welcome to basic networking
     
  7. Killzonetheone

    Killzonetheone

    Joined:
    May 4, 2024
    Posts:
    6
    After doing a lot of reading and getting help from network technician friends, it has now worked. There were several errors in the configuration of the server. After everything was fixed, a client was able to connect for the first time. I am relieved