Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Discussion Can't connect to Dedicated Linux Server running with WSL

Discussion in 'Netcode for GameObjects' started by Lemior, Mar 18, 2023.

  1. Lemior

    Lemior

    Joined:
    Nov 12, 2020
    Posts:
    6
    I'm currently playing around with Netcode for Gameobjects. I created a really simple Game where you can join a server and run around a plane as a bean. When i make a build for the game everything works fine. I can let it run a s a server and connect as a client or let it run as a host and then connect with an other client. Everything works perfectly.

    In the next step i tried to let it run as a dedicated server. When i build a dedicated windows server everything works still as expected but when i let it run as dedicated linux server it does not work. I can start the server without a problem. It also outputs the same logs like the windows server but when i try to connect to the server as a client nothing happens. The console outputs "[Netcode] Syncing Time To Clients" all the time and nothing else. After a while i get a timeout on my client (Editor). Im running the dedicated linux server with WSL (Ubuntu) and Windows 11.

    I tried to run the server as sudo but it did not change anything.
    I also tried to add a new rule to my firewall to allow the port 9000 for private networks.

    Here is my Setup:
    NetworkManager Settings:
    upload_2023-3-18_19-15-37.png

    Server Startup Script:
    Code (CSharp):
    1. public class Server : MonoBehaviour
    2. {
    3.     private void Start()
    4.     {
    5.           Debug.Log("Start Server");
    6.           NetworkManager.Singleton.StartServer();
    7.     }
    8. }
    Player Prefab Script:
    Code (CSharp):
    1. public class PlayerNetwork : NetworkBehaviour
    2. {
    3.     #region Variables
    4.  
    5.     // >> Private
    6.     private Vector3 m_moveDir = Vector3.zero;
    7.  
    8.     public float m_moveSpeed = 3f;
    9.  
    10.     // << Private
    11.  
    12.     #endregion Variables
    13.  
    14.     #region Unity Functions
    15.  
    16.     public override void OnNetworkSpawn()
    17.     {
    18.         Debug.Log("Spawn");
    19.     }
    20.  
    21.     private void Update()
    22.     {
    23.         if (!IsOwner)
    24.             return;
    25.  
    26.         if (Input.GetKey(KeyCode.W))
    27.             MovePlayerServerRpc(KeyCode.W, new ServerRpcParams());
    28.         if (Input.GetKey(KeyCode.S))
    29.             MovePlayerServerRpc(KeyCode.S, new ServerRpcParams());
    30.         if (Input.GetKey(KeyCode.A))
    31.             MovePlayerServerRpc(KeyCode.A, new ServerRpcParams());
    32.         if (Input.GetKey(KeyCode.D))
    33.             MovePlayerServerRpc(KeyCode.D, new ServerRpcParams());
    34.     }
    35.  
    36.     #endregion Unity Functions
    37.  
    38.     [ServerRpc]
    39.     private void MovePlayerServerRpc(KeyCode keyCode, ServerRpcParams serverRpcParams)
    40.     {
    41.         Debug.Log("Client with ID " + serverRpcParams.Receive.SenderClientId + " pressed the Key: " + keyCode.ToString());
    42.  
    43.         m_moveDir = Vector3.zero;
    44.         if (keyCode == KeyCode.W) m_moveDir.z = 1f;
    45.         else if (keyCode == KeyCode.S) m_moveDir.z = -1f;
    46.         else if (keyCode == KeyCode.A) m_moveDir.x = -1f;
    47.         else if (keyCode == KeyCode.D) m_moveDir.x = 1f;
    48.         transform.position += m_moveDir * m_moveSpeed * Time.fixedDeltaTime;
    49.     }
    50. }
    51.  
    I'm using Unity 2021.3.7f1

    Edit: I tested it with Unity 2022.2.11f1. It behaves the same.

    Thank you for your help.
     
    Last edited: Mar 19, 2023
  2. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    302
    Hi @Lemior , where is this running? Is it on your local machine?
     
  3. Lemior

    Lemior

    Joined:
    Nov 12, 2020
    Posts:
    6
    Hello.

    Yeah it is running on my PC. I uploaded the Linux Build to a Unity Linux Game Server and it works there.
    Therefore it is a problem on my PC.

    Originally i just wanted to test it on my local machine before uploading it to save time. Because it works with Unity Game Server Hosting, which was my goal from the beginning, i did not further investigate this problem and started to using the Game Server Hosting directly.
     
  4. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    302
    Are you launching the build with the same set of parameters Game Server Hosting sends to it?
     
  5. Lemior

    Lemior

    Joined:
    Nov 12, 2020
    Posts:
    6
    I tried it without and with parameters. I used: ./Multiplayer.x86_64 -nographics -port $$port$$ -queryport $$query_port$$.
    These are the same for Game Server Hosting
     
  6. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    302
    There's where the problem lies: when running on Game Server Hosting, "$$port$$" (and other similar parameters) will be swapped with a value that Game Server Hosting assigns. I.E: $$port$$ will be 34567.

    When running on your machine, you need to specify these values manually, so you should use something like:

    Code (CSharp):
    1. ./Multiplayer.x86_64 -nographics -port 34567 -queryport 45678.
    And the you'll need to make sure your clients use the same numbers when they try connecting to the server.

    Does this help?
     
  7. Lemior

    Lemior

    Joined:
    Nov 12, 2020
    Posts:
    6
    I used
    Code (CSharp):
    1. ./Multiplayer.x86_64 -nographics -port 9000 -queryport 45678
    It did not work. My transport settings are as follows:

    upload_2023-3-27_16-45-48.png

    I start the client directly in the network manager with start client. I don't do anything else.
    Therefore the query port should not be relevant right? Or where should i set that?