Search Unity

Resolved Can't connect to dedicated server but working fine with host

Discussion in 'Netcode for GameObjects' started by al33f, Jan 29, 2024.

  1. al33f

    al33f

    Joined:
    Aug 2, 2017
    Posts:
    9
    Hello, I need a bit of help. I put together a quick NGO test with the Starter Assets 3rd person controller. Everything works well if I compile it as host. It binds to all interfaces and the client can connect on either one (localhost and net ip). If I compile the same code as dedicated server (both Win and Linux) it doesn't work. The client connects for a bit but doesn't spawn the player character and on the server logs I get:

    [Netcode] Client Connected
    Received a message with invalid message type value 1
    [Netcode] Server detected a transport connection from Client-1, but timed out waiting for the connection request message.
    [Netcode] Client Connected
    Received a message with invalid message type value 1
    [Netcode] Disconnect Event From 2
    [Netcode] ShutdownInternal
    [Netcode] NetworkConnectionManager.Shutdown() -> IsListening && NetworkTransport != null -> NetworkTransport.Shutdown()

    This is all I get even with the Developer log level.
    The only change I make between the builds is in one file:
    For dedicated server:
    private void Awake()
    {
    if (!NetworkManager.Singleton.IsClient && !NetworkManager.Singleton.IsServer)
    {
    NetworkManager.Singleton.StartServer();
    }
    }

    For client/host:
    void OnGUI()
    {
    GUILayout.BeginArea(new Rect(10, 10, 300, 300));
    if (!NetworkManager.Singleton.IsClient && !NetworkManager.Singleton.IsServer)
    {
    StartButtons();
    ip = GUILayout.TextField(ip, 16);
    port = GUILayout.TextField(port, 5);
    if(GUILayout.Button("Connect to " + ip + ":" + port)) Connect(ip, port);
    }

    GUILayout.EndArea();

    }
    private void Connect(string ip, string port)
    {
    ushort _port = Convert.ToUInt16(port);
    NetworkManager.Singleton.GetComponent<UnityTransport>().SetConnectionData(ip, _port);
    NetworkManager.Singleton.StartClient();
    }
    static void StartButtons()
    {
    if (GUILayout.Button("Host")) NetworkManager.Singleton.StartHost();
    if (GUILayout.Button("Client")) NetworkManager.Singleton.StartClient();
    if (GUILayout.Button("Server")) NetworkManager.Singleton.StartServer();
    }

    If anyone has any sort of feedback I'd really appreciate it. Thanks.
     
    Last edited: Jan 29, 2024
  2. al33f

    al33f

    Joined:
    Aug 2, 2017
    Posts:
    9
    I just checked. With the GUI build (client/host), even if I start it as server it still works fine and I can connect the clients. I'm not sure if that adds anything useful but I thought I'd mention it.
     
  3. al33f

    al33f

    Joined:
    Aug 2, 2017
    Posts:
    9
    Ok, for the dedicated server I had to run the server in Start not in Awake. This fixed the issue.
     
    Last edited: Jan 29, 2024
  4. NoelStephens_Unity

    NoelStephens_Unity

    Unity Technologies

    Joined:
    Feb 12, 2022
    Posts:
    257
    Glad to hear you got it figured out.