Search Unity

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

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

  1. MihkelT

    MihkelT

    Joined:
    Sep 18, 2014
    Posts:
    21
    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.
     
  2. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
  3. MihkelT

    MihkelT

    Joined:
    Sep 18, 2014
    Posts:
    21
    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.
     
  4. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    @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.
     
  5. FranknSon

    FranknSon

    Joined:
    May 27, 2017
    Posts:
    19
    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
     
  6. FranknSon

    FranknSon

    Joined:
    May 27, 2017
    Posts:
    19
    Also using Lobby Manager for Matchmaking.
     
  7. Zebadiah

    Zebadiah

    Joined:
    Apr 6, 2014
    Posts:
    67
    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.
     
  8. MariuszKowalczyk

    MariuszKowalczyk

    Joined:
    Nov 29, 2011
    Posts:
    301
    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?
     
  9. MihkelT

    MihkelT

    Joined:
    Sep 18, 2014
    Posts:
    21
    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?
     
  10. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    @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.
     
  11. thegreatzebadiah

    thegreatzebadiah

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

    MihkelT

    Joined:
    Sep 18, 2014
    Posts:
    21
    @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
  13. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    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?
     
  14. MihkelT

    MihkelT

    Joined:
    Sep 18, 2014
    Posts:
    21
    @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
  15. MihkelT

    MihkelT

    Joined:
    Sep 18, 2014
    Posts:
    21
    @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
  16. MihkelT

    MihkelT

    Joined:
    Sep 18, 2014
    Posts:
    21
    @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).
     
  17. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    @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
     
  18. jhbyhuangzejie

    jhbyhuangzejie

    Joined:
    Mar 10, 2017
    Posts:
    7
    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
  19. jhbyhuangzejie

    jhbyhuangzejie

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

    jhbyhuangzejie

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

    Erdal42

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

    THIS PROJECT IS DEAD.
    DO NOT BUY
     
  22. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    589
    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.
     
  23. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    589
    @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.
     
  24. Zebadiah

    Zebadiah

    Joined:
    Apr 6, 2014
    Posts:
    67
    @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.
     
  25. BonneCW

    BonneCW

    Joined:
    Jan 22, 2017
    Posts:
    123
    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.
     
  26. Zebadiah

    Zebadiah

    Joined:
    Apr 6, 2014
    Posts:
    67
    @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.
     
    PutridEx likes this.
  27. MariuszKowalczyk

    MariuszKowalczyk

    Joined:
    Nov 29, 2011
    Posts:
    301
    I use 1.63. I have found the device properly and run the mapPort function. But I am waiting for the onPortMappingDone function to be run forever. There is no error no anything. The timeout is set to 10 (I assume it's in seconds).

    This problem probably occurs only in some particular settings/routers. I remember that it was working fine in the past when I was testing it with another router. I will try to ask other people to test this. I have also seen that some years ago someone had this problem and you have added the timeout to solve this.

    After the timeout, is there any callback function or any other way to check if the timeout took place? I have no error, nothing.

    Same thing happens in your ExampleNATHelperOnly, but in the end I was able to make it work in your example (details below), so I will now try to make it work in my code.

    The problem was that I was trying to use natHelper like this atHelper = new NATTraversal.NATHelper(), rather than like a component. After switching to the component the function is working, but the port forwarding failed. I will try to solve this.

    Looks like the problem occurs when the public port and private port are the same. Hmm...

    I have been able to make it work (at least it says that the ports have been forwarded properly) (after switching the build type in the editor from Windows to Mac, I am on Mac). But it worked only once and I see some exceptions:

    NATHelper: Port Mapping callback threw exception: Object reference not set to an instance of an object
    UnityEngine.Debug:Log(Object)
    NATTraversal.NATHelper:Update() (at E:/_Noble Whale/NAT Traversal/NAT Traversal DLL/NATTraversalForUNET/NATHelper.cs:366)

    at NATHelperTester.onPortMappingDone (Open.Nat.Mapping mapping, Boolean isError, System.Exception e) [0x0000e] in Assets/NAT Traversal Example/Extras/NAT Helper/NATHelperTester.cs:106
    at NATTraversal.NATHelper+PortMappingDoneInfo.fireEvent () [0x00008] in E:\_Noble Whale\NAT Traversal\NAT Traversal DLL\NATTraversalForUNET\NATHelper.cs:288
    at NATTraversal.NATHelper.Update () [0x00063] in E:\_Noble Whale\NAT Traversal\NAT Traversal DLL\NATTraversalForUNET\NATHelper.cs:362
    UnityEngine.Debug:Log(Object)
    NATTraversal.NATHelper:Update() (at E:/_Noble Whale/NAT Traversal/NAT Traversal DLL/NATTraversalForUNET/NATHelper.cs:367)

    NATHelper: Port Mapping callback threw exception: Object reference not set to an instance of an object
    UnityEngine.Debug:Log(Object)
    NATTraversal.NATHelper:Update() (at E:/_Noble Whale/NAT Traversal/NAT Traversal DLL/NATTraversalForUNET/NATHelper.cs:366)

    at NATHelperTester.onPortMappingDone (Open.Nat.Mapping mapping, Boolean isError, System.Exception e) [0x0000e] in Assets/NAT Traversal Example/Extras/NAT Helper/NATHelperTester.cs:106
    at NATTraversal.NATHelper+PortMappingDoneInfo.fireEvent () [0x00008] in E:\_Noble Whale\NAT Traversal\NAT Traversal DLL\NATTraversalForUNET\NATHelper.cs:288
    at NATTraversal.NATHelper.Update () [0x00063] in E:\_Noble Whale\NAT Traversal\NAT Traversal DLL\NATTraversalForUNET\NATHelper.cs:362
    UnityEngine.Debug:Log(Object)
    NATTraversal.NATHelper:Update() (at E:/_Noble Whale/NAT Traversal/NAT Traversal DLL/NATTraversalForUNET/NATHelper.cs:367)
     
    Last edited: Nov 26, 2020
  28. MariuszKowalczyk

    MariuszKowalczyk

    Joined:
    Nov 29, 2011
    Posts:
    301
    There is probably a bug, as when I use LogFilter.currentLogLevel = LogFilter.Debug; I see the port forwarding is done properly (according to the logs, I don't know for sure), but the OnPortMappingDone() shows failed. Also the e object is always null.

    There is no indication that the port has been forwarded in the router panel or netstat -a, so I assume it failed. Also some players have problems with connection, so something is wrong. I have try even the example, but the same problem there.

    Also I was calling stopPortForwarding after the finish of port forwarding. Maybe it was the reason for the ports to not working. I thought (from your docs) that it only stops the nat traversal activities not the port forwarding itself, as there is the remove function for such removal. So stopPortForwarding may be the problem? I will update the game soon and check if it helped players.
     
    Last edited: Nov 30, 2020
  29. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    @MariuszKowalczyk Unfortunately NAT Traversal is no longer supported moving forward. It is provided as-is on the Asset Store for anyone who still finds it useful, but there will be no further changes or fixes. If you would like a refund just let me know.

    I highly recommend you give the new Noble Connect asset a try instead. It is free to try, and does everything NAT Traversal does and then some.
     
  30. MariuszKowalczyk

    MariuszKowalczyk

    Joined:
    Nov 29, 2011
    Posts:
    301
    Thank you for the answer. There is no need to refund. I am using your plugin since 2017.

    Also I use Unity 5.5.3f1 for the game we are talking about here and I can not upgrade it. I use the very old Unity networking there (that one before the UNet) etc. Noble Connect would work in this environment?

    I only need Port Forwarding, nothing more. I don't see this on the feature list of Noble Connect.

    Could you answer one question about NAT Traversal? If the LogFilter.Debug shows that the port has been forwarded, but the OnPortMappingDone() shows the error. The port has been forwarded or not? Also what is the best way to check, netstat? In my router I don't see any indication of the port forwarding (on my old one I remember that I was able to see the forwarding and it was working for sure).
     
  31. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    @MariuszKowalczyk It seems like that stack trace is indicating that an exception is being thrown in the callback method, onPortMappingDone in the NATHelperTester. So it seems like everything is going right up until there. I would look at the offending line and see why it is crashing. I assume you've modified your NATHelperTester, as it doesn't seem like line 106 in my version would cause a crash. Once you get that method to not crash you can check if success is true to confirm. Either way though if your log level is set to "Developer" you should see all the active mappings printed out. If it's in that list then the port is forwarded.

    P.S. Seems like Noble Connect won't work for you unfortunately. It could be made to work with the old networking, but it doesn't include port forwarding anyway. It seemed unnecessary with punchthrough and relays doing the same job.
     
  32. MariuszKowalczyk

    MariuszKowalczyk

    Joined:
    Nov 29, 2011
    Posts:
    301
    Thank you for the advice, in Unity 5.5.3f1 the Developer level is not available due to the protection level (looks like it is private). That's weird, I will try to investigate this more, maybe there is some way to go around this.

    The exception is due to the Exception e object being null all the time.