I have a unity network server (i start the server with NetworkManager.StartServer(); ) that i build headless for linux.
My problem is that my server doesn’t bind to both ipv6 and ipv4 addresses of the server.
- I tried to give it a host that resolves into both ipv6 and ipv4.
- I tried to give it an empty string as an address (since I presume this is what triggers the underlying layer to use INADDR_ANY)
- I tried to give it(serverBindAddress) the value of 0
- toggled serverBindToIP
Any of you have any idea how I could make it listen on both protocols?
2 Likes
I don’t know how great of a solution it is but you could try starting two servers, one to listen on the ipv4 address and another for the ipv6 address. I’ll admit that sounds terrible though. If you do go that route you will probably end up needing this: https://docs.unity3d.com/ScriptReference/Networking.NetworkServer.AddExternalConnection.html
I’d really love to know the proper answer to this though so bump
The only way I could do that is if I would split the MatchMaking part from the game server. Make it listen to both ipv6 and 4 and then feed the connections to a agnostic game server.
But the development is over and I don’t have time to redo everything.
I’ll just use ipv4 since its the most common.
@catalin-ene I have the same problem, but I fail to see how do you consciously switch between IPv4 and IPv6? I have here two builds and somehow each is doing it differently:
netstat -tulpn
udp 0 0 0.0.0.0:7777 0.0.0.0:* 5348/
udp6 0 0 :::7778 :::* 30023/
build2 is not reachable many times (other times it is, then suddenly not anymore, without changing anything not even the build is restarted). In the case it doesn’t work I find this in the client log:
Log: cannot connect after 10 attempt address {::ffff:x.x.x.x:7778}
I come to the same conclusion as you that for now I will just try to run it on IPv4, but I cannot find where to configure it to do so.
As far as I can see I configured the builds in the same way (although they are different projects). Would very much appreciate your help!
You can use the https://docs.unity3d.com/ScriptReference/Networking.NetworkManager-serverBindAddress.html in conjuction with https://docs.unity3d.com/ScriptReference/Networking.NetworkManager-serverBindToIP.html set to true.
If you make the serverbindAddress equal to an IPv4 ip it will listen on that ip. If you give it a host which resolves to both IPv4 and IPv6 it will choose IPv6.
If you are using the NetworkManager component https://docs.unity3d.com/uploads/Main/NetworkManagerMatchmaker.png
you can do the same thing in the network info section.
In my case I just made a config in StreamingAssets that I read at startup and where I can configure the server ip address, port and some other misc stuff.
2 Likes
Thank you so much! We solved the problem with the help of your post!