Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

NAT Traversal - Automatic port forwarding, punch-through, and more!

Discussion in 'Assets and Asset Store' started by thegreatzebadiah, Apr 5, 2016.

  1. Farage

    Farage

    Joined:
    Apr 25, 2014
    Posts:
    31
    Hey Zebadiah
    I'm planning on buying your asset, but since UNet is being deprecated, i'm being held back for not knowing how far or how i can use this
    I am planning however on building the entire server logic into the client and having it NAT punch creating a player-hosted multiplayer logic (listen server logic)
    Is this possible with your asset without using UNet? (and if i may ask, is this possible at all?)
    Thank you in advance
     
  2. trappist-1

    trappist-1

    Joined:
    Mar 26, 2017
    Posts:
    566
    I am in need of upgrading my project to 2019 editor. But this asset shows 118 compile errors. What should I do?
     
  3. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    793
    @trappist-1 You're going to have to wait for 2019 to go live. Unfortunately I do not support beta or alpha versions of the editor. Hopefully by the time it is released I will find a work around for the dependencies on the Networking namespace that is going away. Most of the examples are going to become worthless though as they were built around UNet so it's going to be less straight-forward to use NAT Traversal in the future. I will try and add an example for the new Unity networking. I will not be adding Mirror support due to technical incompatibilities between RakNet and Mirror.

    If you are looking for Mirror support you will have to wait for my next asset to be released, which is punchthrough combined with relays. It is designed in a more flexible way that will be able to support Mirror.
     
  4. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    793
    It sounds like you're describing the standard player-hosted peer-to-peer situation, so yes it is definitely possible. It is also possible without UNet by using the NATHelper, but it will require a bit more setup than the standard UNet stuff. There is an example included that demonstrates how you would use the NAT Helper. The general principles should apply to any UDP socket based networking system (which is most of them, but not Mirror).
     
  5. MihkelT

    MihkelT

    Joined:
    Sep 18, 2014
    Posts:
    9
    Hi, once people have joined the match and everything is ready to go and host starts the actual game, how do I unlist that match from the matchlist? I want to make it so that when host starts the game, players will not see the match in matchlist. I need to either set some data on the match (started = true) or turn off the "advertise" property once the match has started.
     
  6. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    793
  7. MihkelT

    MihkelT

    Joined:
    Sep 18, 2014
    Posts:
    9
    Hi @thegreatzebadiah not using Match UP.

    On a different issue:
    I updated to unity 2019.1 today. Then updated nat traversal. Created new unity project. Imported NAT Traversal. Got 117 errors, starting with:
    "Assets\Plugins\NAT Traversal for UNET\NATLobbyManager.cs(8,30): error CS0234: The type or namespace name 'NetworkSystem' does not exist in the namespace 'UnityEngine.Networking' (are you missing an assembly reference?)"

    What am I missing? I worked with NAT traversal previous version and unity 2018.3 for ~half a year.
     
  8. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    793
    @MihkelT UNet is not longer supported out of the box in Unity 2019.1, and NAT Traversal depends on UNet. You need to import the HLAPI package using the new Unity Package Manager to get access to it.

    As for your matchmaking question, it doesn't really have anything to do with NAT Traversal, so consult the docs for whatever matchmaking system you are using. It may or may not even be possible with UNet matchmaking, but if it is the docs will have the answers.
     
  9. FranknSon

    FranknSon

    Joined:
    May 27, 2017
    Posts:
    15
    I am working with Unity 2018.2 and developing for the Oculus GO (using UNET). We know we need to move to something else but will this work for us (also using a few Mac for development). Thanks
     
  10. FranknSon

    FranknSon

    Joined:
    May 27, 2017
    Posts:
    15
    Also using Lobby Manager for Matchmaking.
     
  11. Zebadiah

    Zebadiah

    Joined:
    Apr 6, 2014
    Posts:
    33
    Nat traversal will work for you as long as you are using unet. If you are planning to move away from Unet eventually though you may want to look in to our newer Noble Connect asset, which works with more networking system such as Mirror and soon the new unity networking.
     
  12. MariuszKowalczyk

    MariuszKowalczyk

    Joined:
    Nov 29, 2011
    Posts:
    247
    I use Unity 5.5.3f1 and I have a big problem with NAT Traversal. My game is freezing when you quit it (not always, but 99% of the time). Here is the game: https://store.steampowered.com/app/485610/Ball_3D_Racing_Soccer__Sports_Games/

    Most (if not all) people have this problem. It started after I have added NAT traversal. I have updated to the newest version and it's the same.

    How can I solve this?
     
  13. MihkelT

    MihkelT

    Joined:
    Sep 18, 2014
    Posts:
    9
    When two players connect, host received the first RPC from client with some initial info (player name etc). After that he got this:
    Log: cannot connect after {10} attempt address {::ffff: <my ip here>}

    Which is really weird, because the first message from client to host went through. I have seen this with 2 different people and for them it's 100% consistent. If the client and host swith roles, then it doesnt work the same way.

    Host can send messages to client (e.g. chat) but client cant send them to host. Except the first message that client sends, which always goes through.

    I have played the game with 5-6 other people 50+ times and with others it has never happened.

    Unity relay servers are enabled! It first connects through relay. Then it works. Then it "ugprades" it to punchthrough but fails. it should switch back to relay but it doesnt switch back :(

    Any suggestions?
     
  14. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    793
    @MihkelT It kind of sounds like there may be a firewall blocking the connection on one end or the other. That's usually the cause when the punchthrough connection seems to work but then fails.
     
  15. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    793
    @MariuszKowalczyk Really not sure. Might need you to send me your project or at least some logs.
     
  16. MihkelT

    MihkelT

    Joined:
    Sep 18, 2014
    Posts:
    9
    @thegreatzebadiah Thank you for replies! I'm a bit concerned that by external IPV4 and IPV6 sources will not be available 24/7. I would like to have a backup list. Is there a built-in way to add more than one source? If not, I would have my own list of sources, find a source that is currently responding and then start nattraversal with that source. Is that the correct way to go about it?


    Another question, I've set up my own facilitator based on http://nattraversal.noblewhale.com/faq/#h3_7
    When the script that is starting Facilitator after reboot starts the Facilitator it will say:
    using port 0
    However if I start the facilitator myself it uses port 61111 which is correct.
    How do I make the bash script set the right port? I tried sth like
    until /home/facilitator/Facilitator -v -p 61111
    and with "" and ' but it doesnt set the port. It still says port is 0
     
    Last edited: Nov 14, 2019
  17. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    793
    There is no built in way to add more than one source, but your way seems like it would work fine.

    I'm not sure about your port issue. You should be able to start the facilitator on any port you want using -p. I don't know why it would work manually but not via script. Maybe the script is running too early after reboot and that is somehow causing some problems?
     
  18. MihkelT

    MihkelT

    Joined:
    Sep 18, 2014
    Posts:
    9
    @thegreatzebadiah Thanks but setting the port doesnt work even if I start the script manually. I'm running it from Putty on AWS ubuntu server.
    This works fine, creates port 61111: ./Facilitator.sh
    This does not work, creates port 0 ./Facilitator.sh -p 61111
    Whatever port I put there it says it runs on port 0. Even when running from command line.

    So I tried to put it in the script without specifying port and then run the script from command line. Like:
    sleep 3;
    until /home/ubuntu/Facilitator -v; do
    echo "Facilitator crashed with exit code $?. Respawning.." >&2
    sleep 1
    done
    echo "done";

    But if I do it from script without port it also starts on port 0
     
    Last edited: Nov 18, 2019
  19. MihkelT

    MihkelT

    Joined:
    Sep 18, 2014
    Posts:
    9
    @thegreatzebadiah are you sure the port parameter works in current version of the facilitator? Referring to previous post.

    Another question. Is there a regional limit on NAT Traversal side that prevents people from connecting too far? I had a player who could play with his 2 friends in US but couldn't play with a guy from Australia and also not connect to 3 people in Europe. It's not a matter of ping but they were not even able to connect.
    => Turns out the issue was that matchlist was empty. The matches were not shown to each-other.
     
    Last edited: Dec 5, 2019
  20. MihkelT

    MihkelT

    Joined:
    Sep 18, 2014
    Posts:
    9
    @thegreatzebadiah I'm trying to launch my own matchmaking based on this http://nattraversal.noblewhale.com/faq/#h3_13

    The match data is set to steam lobby and retrieved on client side, that part is ok. The client tries to connect with startclientall using the IP-s.

    However the connection only works directly. Relay connection always fails. After getting:
    MatchMakingClient Join :https://mm.unet.unity3d.com/json/reply/JoinMatchRequest

    The client get's error: OnClientStartedCustom: success: False
    extendedinfo: failed: Failed enumerating host node id appId=8158902. Match is likely unavailable, please select another to join. matchinfo.networkid: 0

    OnClientStartedCustom is callback of startclientall (data response delegate).
     
  21. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    793
    @MihkelT Sorry to have ignored you for so long. What version of ubuntu are you running so I can check the port issue on that specifically.

    The relay connection error sounds like you're either not passing in the UNet match ID to StartClientAll or you are passing in an invalid one. You should make sure the match you are trying to join was created in the same region as the client that is trying to join it.

    If you join our discord you can get faster / more direct support: https://discord.gg/xBvnCqP
     
  22. jhbyhuangzejie

    jhbyhuangzejie

    Joined:
    Mar 10, 2017
    Posts:
    6
    I plan to use it for commercial projects. Are there any restrictions? Or are there other charges, and are there restrictions on RakNet charges? Thank you
     
    Last edited: Apr 5, 2020
  23. jhbyhuangzejie

    jhbyhuangzejie

    Joined:
    Mar 10, 2017
    Posts:
    6
      • I want to release UWP platform support? thank you
     
  24. jhbyhuangzejie

    jhbyhuangzejie

    Joined:
    Mar 10, 2017
    Posts:
    6
    upload_2020-4-5_15-27-27.png
    Why did the IP(103.228.204.53) assignment fail?
     
  25. Erdal42

    Erdal42

    Joined:
    Sep 17, 2018
    Posts:
    19
    Just joined the Discord...

    THIS PROJECT IS DEAD.
    DO NOT BUY
     
  26. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    474
    This project is still very much alive. We've just been a bit busy lately trying to get out some fixes and dealing with the latest world changes. Anyone always feel free to poke us again via email, forums, store pages, issue tracker, youtube, discord, etc. Cheers.
     
  27. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    474
    @jhbyhuangzejie
    Feel free to release your projects that use NAT Traversal, that's why we sell it to you all of course. But don't just sell our asset to other people if that's what you mean.
    For raknet charges: We host a Facilitator that you are welcome to use free of charge. The Facilitator executable is also included so you can host it on your own server instead. If we notice a ton of cost to us from this, we may cut it off but I don't see that happening.
    I'll have to look deeper into your other questions. I'll respond shortly.
     
  28. Zebadiah

    Zebadiah

    Joined:
    Apr 6, 2014
    Posts:
    33
    @jhbyhuangzejie UWP won't be happening sorry. NAT Traversal is more or less replaced by our new Noble Connect service. We still provide NAT Traversal as is and put out updates for any major fixes but we won't be adding any new features.

    I'll have to look in to the IP Address issue. Thanks for reporting it.
     
  29. BonneCW

    BonneCW

    Joined:
    Jan 22, 2017
    Posts:
    81
    Is il2cpp supported by the plugin? I get exception when trying to connect to the faciliator:

    Code (CSharp):
    1. NotSupportedException: To marshal a managed method, please add an attribute named 'MonoPInvokeCallback' to the method definition. The method we're attempting to marshal is: RakNet.RakNetPINVOKE+SWIGExceptionHelper::SetPendingApplicationException
    2. RakNet.RakNetPINVOKE+SWIGExceptionHelper..cctor () (at <00000000000000000000000000000000>:0)
    3. RakNet.RakNetPINVOKE..cctor () (at <00000000000000000000000000000000>:0)
    4. RakNet.RakPeerInterface.GetInstance () (at <00000000000000000000000000000000>:0)
    5. NATTraversal.NATHelper+d__68.MoveNext () (at <00000000000000000000000000000000>:0)
    It works in the editor though, just the il2cpp build fails and so no multiplayer is possible anymore.
     
  30. Zebadiah

    Zebadiah

    Joined:
    Apr 6, 2014
    Posts:
    33
    @BonneCW Unfortunately NAT Traversal does not support IL2CPP. The RakNet library that powers everything is written in c++ and something about the IL2CPP conversion messes up the existing c++/c# wrappers that the plugin uses. Support for IL2CPP will probably never be added, I wouldn't even know where to begin to solve that, and NAT Traversal has reached end-of-life anyway. It's really only still on the store for anyone stuck using UNet and the old relays and only receives updates for critical fixes of existing features.

    You probably want to look in to Noble Connect instead, which does everything NAT Traversal does and more, and it's written entirely in c# so it doesn't have issues with IL2CPP.
     
unityunity