I want to bind the unity transport (direct without relay) to a specific local port (7777). The port is available (netstat -an | find “7777” return nothing, + more check in script)
but after setting the network endpoint to 7777, it bind to a random port. (wireshark check)
Is there a right way to do this ?
NetworkEndpoint serverEndpoint = NetworkEndpoint.Parse(LobbyManager.instance.Host_Ip, (ushort)LobbyManager.instance.Host_Port);
ushort localPort = 7777;
NetworkEndpoint localEndpoint = NetworkEndpoint.Parse("0.0.0.0", localPort);
unityTransport.SetConnectionData(serverEndpoint, localEndpoint);
networkManager.StartClient();
The important part is: can clients connect through port 7777 on the server’s IP regardless of what wireshark says?
no because the server has its nat open for incoming packets with 7777 port source only.
Is the server behind a router? If so, you’d also need to set up port forwarding and use the router’s public-facing IP as the server IP.
I’ll rephrase the question: Can client processes that run locally on the server machine connect to the server instance on port 7777? If so, not being able to connect from another machine is a routing issue.
the issue is that unity transport has tools and settings to set a local port but it doesn’t work. I will not need port forwarding if I can make it work on this specific port.
The Unity Transport package does support binding clients to a specific port, but currently its wrapper in NGO does not expose this functionality. Clients in NGO are always bound to an ephemeral port.
Currently your only option would be to modify the NGO package to override the default behavior. You’ll need to modify function ClientBindAndConnect
in UnityTransport.cs
so that the call to m_Driver.Bind
is performed with an endpoint with the desired port (e.g. m_Driver.Bind(bindEnpoint.WithPort(YOUR_PORT))
.
I’d also suggest opening a feature request here if you want to see this added to NGO eventually.
that made me dive a bit more into package management as I was unable to correctly edit the file. I was trying to edit the cached version of NetworkDriver.Bind() directly.
Final hack in UnityTransport :
I think it should be good thanks.