How can I use NAT Traversal with UNET? Only for users that pay?

Hi guys,

I just spend a week updating my own network library to build on top of the new UNET. The only problem: how can I allow two users behind a NAT/Firewall/Router to connect to each other? It seems the new system doesn’t contain any nat traversal mechanism anymore?!?

Thanks

Luz

Good question. They gave us relay server to avoid NAT issues, but it will introduce severe ping times (especially on fully authoritative games), concurrent connections limit, charges for usage, and message per second limitations.
From my point of view there’s no point creating a copy of Photon. I actually liked RakNet for NAT punch-through.

I’m trying to find info how to implement automatic port forwarding or NAT punching for the dedicated servers (so clients don’t need to deal with any routing issues, just connect to public IP).

This looks like a solution at the first glance, trying it out right now.
It doesn’t compile on Unity3D because mono is extremely old, but I will try to use it as an external executable.
You can run external .exe from Unity3D. Running an external EXE file from Unity - Questions & Answers - Unity Discussions

Another thing to look at is GitHub - nterry/Mono.Nat: NAT stack for Mono and .NET applications
This might compile on Unity, didn’t try it yet tho

1 Like

Totally agree!

As for NAT punching, a dev stated somewhere that they were thinking about it.

Good news. GitHub - nterry/Mono.Nat: NAT stack for Mono and .NET applications did actually compile on Unity3D.
Here is how to use it.
UPNP port forwarding – The easy way | Fluxbytes
mono-nat - Main page - Projects hosted by qNETp
It says that it will even work on Android. I’l do some tests tomorrow and post results here.

If it works - then all you would need is a custom master server, which is dead easy to create using any tools and programming language. Yay I think we could get our raknet features back.

1 Like

I just have tested it on 2 PCs with 2 different public IP addresses. One behind uPnP-enabled router (NAT), while other is directly connected.
Hosted a game on a PC behind router, did port mapping via Mono.Nat, and connected to it from the other pc - this worked perfectly fine.
Then I tried it without Mono.Nat - connection didn’t work.
So yep, Mono.Nat works.

Seems like it supports not only uPnP, but PMP too. It means that garbage Apple routers should still work with it. (not tested)

FYI, Mono.Nat is insanely buggy, and while it does work on some routers in my experience it will fail on a ton of them. I did extensive testing of Mono.Nat for Bolt, and while Bolt still uses Mono.Nat since no other free option is available, don’t bet on it actually working on a production environment.

1 Like

Thanks for this very useful info. I see that they update it quite often. https://www.nuget.org/packages/Mono.Nat/
What version did you test?

1.2.21 IIRC, I tested Mono.Nat in both a development environment (about ~20-30 different routers makes/models in total) and also in a production environment in the game ‘The Forest’.

It simply does not work reliably.

5 Likes

Good informations + 1

Oh I didn’t notice that someone actually answered in the end :o

I look into webrtc for now as I will try my best to get my game running in WebGL. It supports nat traversal. Until I get this working I am back to the old unity networking :confused:

Hi guys,

I’m the Open.NAT developer. Please if you find it defects, just create an issue in github and I will fix it asap.

Thx

This makes the library immediately look much more reliable :slight_smile: Will give it a try soon

Hi all,

I proposed a backport of Open.Nat to Net 3.5:

If you test it in Unity, please give me some feedback.

Thank you,

Michael

1 Like

Are we supposed to compile it outside Unity3D ? I defined NET35 and it still doesn’t work

– EDIT:
Yep. Compiled it, so now it works just fine. Thanks m8.

Getting weird results though. GetExternalIPAsync gives me 10.19.52.17 instead of my actual public ip address.
Owait, that’s my router or ISP doing something stupid.

@michael.catanzariti Really appreciate you porting Open.NAT to work with unity! Just wondering, all these Async calls that use System.Threading.Task 's. I haven’t had any luck using Tasks in Unity. Am I supposed to avoid the async calls? or am I using Tasks wrong

HI, does it work for Android App?

HI, have you tried Open.Nat in Android App? it seems not work well, “Can’t find libc”

It does compile, but it doesn’t work due to security I guess.

@shame How did you get the library to compile? Also did it compile on MAC or PC?

Hi guys, I think I’ve come up with a solution for NAT Punchthrough: UNet and Nat Punchthrough. It can be done! - Unity Engine - Unity Discussions

The example there doesn’t include automatic port forwarding but if there is interest I can put one together. I was able to get Open.NAT compiled on windows without any major problems and the port forwarding seems to work, at least in my tests so far.