Search Unity

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

Discussion in 'UNet' started by devluz, Jun 22, 2015.

  1. devluz

    devluz

    Joined:
    Aug 20, 2014
    Posts:
    66
    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
     
  2. forcepusher

    forcepusher

    Joined:
    Jun 25, 2012
    Posts:
    227
    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).

    https://github.com/lontivero/Open.NAT
    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. http://answers.unity3d.com/questions/16675/running-an-external-exe-file-from-unity.html

    Another thing to look at is https://github.com/nterry/Mono.Nat
    This might compile on Unity, didn't try it yet tho
     
    Last edited: Jun 29, 2015
    HugoZandel likes this.
  3. HugoZandel

    HugoZandel

    Joined:
    Mar 11, 2014
    Posts:
    52
    Totally agree!

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

    forcepusher

    Joined:
    Jun 25, 2012
    Posts:
    227
    HugoZandel likes this.
  5. forcepusher

    forcepusher

    Joined:
    Jun 25, 2012
    Posts:
    227
    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)
     
  6. fholm

    fholm

    Joined:
    Aug 20, 2011
    Posts:
    2,052
    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.
     
    forcepusher likes this.
  7. forcepusher

    forcepusher

    Joined:
    Jun 25, 2012
    Posts:
    227
    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?
     
  8. fholm

    fholm

    Joined:
    Aug 20, 2011
    Posts:
    2,052
    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.
     
    Knowckx, -chris, GoGoGadget and 2 others like this.
  9. HugoZandel

    HugoZandel

    Joined:
    Mar 11, 2014
    Posts:
    52
    Good informations + 1
     
  10. devluz

    devluz

    Joined:
    Aug 20, 2014
    Posts:
    66
    Oh I didn't notice that someone actually answered in the end :eek:

    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 :/
     
  11. lontivero

    lontivero

    Joined:
    Sep 19, 2015
    Posts:
    1
    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
     
  12. devluz

    devluz

    Joined:
    Aug 20, 2014
    Posts:
    66
    This makes the library immediately look much more reliable :) Will give it a try soon
     
  13. michael.catanzariti

    michael.catanzariti

    Joined:
    Aug 25, 2015
    Posts:
    2
    forcepusher likes this.
  14. forcepusher

    forcepusher

    Joined:
    Jun 25, 2012
    Posts:
    227
    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.
     
    Last edited: Nov 14, 2015
  15. james69lemon

    james69lemon

    Joined:
    Nov 24, 2013
    Posts:
    6
    @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
     
  16. KEN

    KEN

    Joined:
    Oct 19, 2012
    Posts:
    3
    HI, does it work for Android App?
     
  17. KEN

    KEN

    Joined:
    Oct 19, 2012
    Posts:
    3
    HI, have you tried Open.Nat in Android App? it seems not work well, "Can't find libc"
     
  18. forcepusher

    forcepusher

    Joined:
    Jun 25, 2012
    Posts:
    227
    It does compile, but it doesn't work due to security I guess.
     
  19. BeardOfFury

    BeardOfFury

    Joined:
    Sep 4, 2012
    Posts:
    18
    @shame How did you get the library to compile? Also did it compile on MAC or PC?
     
  20. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    Hi guys, I think I've come up with a solution for NAT Punchthrough: http://forum.unity3d.com/threads/unet-and-nat-punchthrough-it-can-be-done.391845/

    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.
     
  21. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    Hi again, just wanted to update anyone following this thread. Unfortunately the link I posted above is no longer valid.

    The good news is that the NAT traversal stuff I was working on has become much more full featured and is now available on the asset store. It's got automatic port-forwarding, NAT punch-through, and some other cool stuff.

    Check out the forum post for more info or get it here.

    Thanks everyone. The info in this thread was really helpful.
     
    Wattosan and jinnindo like this.
  22. Ursinho

    Ursinho

    Joined:
    Jun 26, 2013
    Posts:
    1
    Couldn't install Open.Nat

    Here's what I get:

    Attempting to gather dependencies information for package 'Open.Nat.2.0.16' with respect to project 'Network.CSharp.Editor', targeting '.NETFramework,Version=v3.5,Profile=Unity Full v3.5'
    Attempting to resolve dependencies for package 'Open.Nat.2.0.16' with DependencyBehavior 'Lowest'
    Resolving actions to install package 'Open.Nat.2.0.16'
    Resolved actions to install package 'Open.Nat.2.0.16'
    Attempting to gather dependencies information for package 'Open.Nat.2.0.16' with respect to project 'Network.CSharp', targeting '.NETFramework,Version=v3.5,Profile=Unity Subset v3.5'
    Attempting to resolve dependencies for package 'Open.Nat.2.0.16' with DependencyBehavior 'Lowest'
    Resolving actions to install package 'Open.Nat.2.0.16'
    Resolved actions to install package 'Open.Nat.2.0.16'
    Attempting to gather dependencies information for package 'Open.Nat.2.0.16' with respect to project 'Network.CSharp.Plugins', targeting '.NETFramework,Version=v3.5,Profile=Unity Subset v3.5'
    Attempting to resolve dependencies for package 'Open.Nat.2.0.16' with DependencyBehavior 'Lowest'
    Resolving actions to install package 'Open.Nat.2.0.16'
    Resolved actions to install package 'Open.Nat.2.0.16'
    Install failed. Rolling back...
    Package 'Open.NAT.2.0.16 : ' does not exist in project 'Network.CSharp.Editor'
    Package 'Open.NAT.2.0.16 : ' does not exist in folder 'C:\Users\ZanoniPC\Documents\Network\packages'
    Could not install package 'Open.NAT 2.0.16'. You are trying to install this package into a project that targets '.NETFramework,Version=v3.5,Profile=Unity Full v3.5', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
    ========== Finished ==========

    Can someone help me?