Search Unity

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

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

  1. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    I've considered it.
     
    cmckelvy and clobo like this.
  2. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    Well, glad you got that sorted out :)
     
  3. Jmangles

    Jmangles

    Joined:
    Aug 1, 2015
    Posts:
    53
    Any idea why in certain special cases I'm getting a NullReferenceException from OnHolePunchedClient?

    I'm just using StartHostAll/StartClientAll and the custom NetworkManager along with the facilitator. I had a tester leave their computer running hosting a match and I'd drop in and out to try to iron out some bugs and for whatever reason after messing around for a while it would say it was trying to go through a hole the facilitator found and then it would give me that NRE. Before it did that though and it was allowing me to connect it was saying something along the lines of "connected through NAT punchthrough despite already being able to connect directly" as the tester has automatic port forwarding.
     
  4. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    @Jmangles I'll need to see the error / stacktrace.
     
  5. Jmangles

    Jmangles

    Joined:
    Aug 1, 2015
    Posts:
    53
    Unfortunately I just can't recreate it yet, if it happens again I'll make sure to screenshot it. What COULD be null in OnHolePunchedClient so I can put in some sort of checks? When it happened I would get the usual Attempting to connect directly message followed by it connecting to the facilitator, sending me a port, and attempting to use that hole. Then I'd get a null reference error and get stuck in a sort of limbo where it wouldn't call disconnect functions but couldn't connect either.

    Also just so I understand the plugin a bit better, sometimes I'll try to connect to someone and it will say it's trying to connect directly and then I'll get disconnected from them without it ever trying to punch a hole, does that mean it tried to punch a hole and couldn't find one? I'm only wondering because in those cases the last console log I get is attempting to connect directly and then after that is a disconnect with no messages about punchthrough.
     
  6. RoyArtorius

    RoyArtorius

    Joined:
    Jul 11, 2013
    Posts:
    73
    Has there been any progress on this or has it been looked into? I'm asking because I'm doing the same thing by allowing the users to create their own dedicated servers. All I really need is a StartServerAll method that simply does not create a hosting client. I wouldn't imagine that would be a complicated change to make but I don't know the code behind it. It would be helpful to know if this being worked on as I will need to develop it myself if it is not and I would hate to have spent a lot of time on developing it when a update comes that basically that nullifies that work.
     
  7. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    Frankly I had forgotten it was an issue (sorry @WaaghMan). I'm looking into it right now. It really shouldn't be too complicated.
     
  8. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    @WaaghMan @ZackLeodrano I just got the dedicated server thing working. It will be in the next update. You can email me at the support email to get it earlier as always.
     
  9. kjuanlu

    kjuanlu

    Joined:
    Dec 4, 2011
    Posts:
    100
    Hello! I read in the FAQ that NAT punch-through works more often if you have at least two public IPs on the server your Facilitator is running on. I'm using the Facilitor on the amazon EC2, and I set up a Elastic IP, do you know how to set up two public IP in order Nat punch-through works more often ?

    Regards
     
    Last edited: Nov 8, 2017
  10. kjuanlu

    kjuanlu

    Joined:
    Dec 4, 2011
    Posts:
    100
    This works!
     
    thegreatzebadiah likes this.
  11. Stabbarey

    Stabbarey

    Joined:
    Sep 3, 2014
    Posts:
    1
    Haven't looked into it much, but would the migrationmanager be easy to automate? Sorry if this was discussed previously. Thanks in advance
     
  12. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    Yeah it should be no problem to automate. Just take a look at what the buttons are doing in the ExampleMigrationManager and do that stuff automatically when the host is lost.
     
  13. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    NAT Traversal 1.57 Released
    • Fixed issues with System.Threading when using .NET 4.6 runtime.
    • Added a readme for converting to 4.6
    • Added example for Match Up matchmaking
    • Cleaned up some harmless warnings
    • Removed some old stuff from Unity 5.2
    • Added dedicated server support
    It is finally possible to start a server without starting a client (dedicated server). I don't know why that wasn't built in to begin with. Thank you @ZackLeodrano and @WaaghMan for bringing it up.

    .NET 4.6 should be fully supported now. I thought it already was but I ran into a few issues that made me re-think things..Make sure to check out the NET46 README if you're looking to get that working.

    The part I'm most excited about is the example for using our new Match Up matchmaking plugin instead of UNET's matchmaking. Unfortunately Match Up isn't actually out yet (we're still awaiting approval) so you'll have to wait a bit before you can start using it. Shout out to @NFMynster for finally convincing me to release a matchmaking plugin. I think you guys are really going to like it. It's super easy to use and super flexible.

    You can see a bit of a sneak preview of Match Up here: http://grabblesgame.com/MatchUp/

    Cheers!
     
  14. ScoobyNooby

    ScoobyNooby

    Joined:
    Nov 14, 2017
    Posts:
    45
  15. WaaghMan

    WaaghMan

    Joined:
    Jan 27, 2014
    Posts:
    245
    Colour me interested for your Match Up plugin! (as long as it supports Steam/PS4/Xbox One cross-platform integration, which I know it's easier said than done).
     
    thegreatzebadiah likes this.
  16. RoyArtorius

    RoyArtorius

    Joined:
    Jul 11, 2013
    Posts:
    73
    Just noticed the update, thanks for adding dedicated server support! Also, I absolutely love what I see with MatchUp. I was quite literally about to dive into Match Making so seeing yet another superior alternative to Unity's own stuff is, well, awesome! Can't wait for its release :D
     
    thegreatzebadiah and ScoobyNooby like this.
  17. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836

    I've looked into Master Server Framework and I *think* it will play nicely. As long as you've got a host and the host connects to the Facilitator to get a guid, and that guid gets to the clients somehow to pass in to StartClientAll then it should be good.

    Match Up is going to be 14$
     
    ScoobyNooby likes this.
  18. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    The client side should run on just about anything unity supports (except WebBuilds because of their weird sockets). The server side you can host on any linux server. I don't think there should be any issues with Steam/PS4/Xbox One. The matchmaking is totally separate from the actual networking so it shouldn't really matter what you're using it for.
     
  19. KaldrisRelm

    KaldrisRelm

    Joined:
    Mar 8, 2014
    Posts:
    10
    Hi @thegreatzebadiah

    Thanks for the recent update! Lots of interesting things to check out. I noticed one problem from moving from 1.56 to 1.57 though. There's a script called 'ExampleMigrationManager.cs' contained in your 'NAT Traversal Example' folder from the 1.56 update. This same script exists in 1.57, however it's been moved to an 'Extras' folder underneath the Example folder.

    I think because of this, the old script isn't removed or updated when the update happens, and you get a namespace violation error message. I've included a screenshot of what the 'Import Unity Package' looks like when importing into a project with 1.56 on it for your review.

    Edit: Game names when using the Lobby System don't show as 'default' in this new version! I've been searching for months trying to figure out what I screwed up to do that! I am very happy.
     

    Attached Files:

    Last edited: Nov 15, 2017
    thegreatzebadiah likes this.
  20. ScoobyNooby

    ScoobyNooby

    Joined:
    Nov 14, 2017
    Posts:
    45
    Ok so I was planning on going photon pun way but then I saw the bright light!
    so just incase there is no light and I'm just seeing things let me double check I have this correct.

    So using your NAT Traversal plugin hosted on a "VPS linode" and on that same vps have your upcoming matchmaking plugin. also have a dedicated host (your new feature) on that same vps. only when p2p fails with NAT Traversal instead of going to use unitys relay I can then use the dedicated host on the VPS linode?

    If this is true then wow. Perfect setup.
    Oh by the way if you do support mobile then I think you need to update your FAQ's. good job on the FAQs.

    ps Match Up,fair price. :)
     
  21. schicki01

    schicki01

    Joined:
    Jun 14, 2017
    Posts:
    8
    Hello guys,

    I have a trouble with the NAT Traversal I just can´t get around. The NAT Helper script is not able to find my Router? I get the warning "NAT Device not found".


    I tested it with the Example-project and my own Server where the Facilitator is running. Connection to the Facilitator works just fine (NetworkManger GameObject with NAT Helper and Example Network Manager scripts attached).
    I´m running on a private 192.168.x.x behind my public ip-address on my Wireless Router.

    I doubt NAT Punchthrough is possible until the NAT Device is found, if I try to connect to the Host Instance I get these Logs (but no connection through it obviously):
    (Tested with a client in a Network with a different Wireless Router, output on Host)


    In case this is a stupid beginner mistake, I deeply apologize, my knowledge in peer-to-peer networking is mediocre at best.
    There was someone on this Thread a year ago who got the same problem, but got it fixed apparently with shifting his scripts around on the GameObject, which does not the trick for me unfortunately. Would be interesting if someone else came across this particular problem, I assume there is a problem with my router?
    I tried assigning a new script which just gets the NAT Helper component and tries to find the router every 3 seconds in the Update function, still nothing.
    (Source code of the FindNatDevice() would be interesting but of course it is not public, doubt it would help me much anyways)

    Any thought on this would be appreciated!
     
  22. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    You know I saw this issue coming and intentionally didn't re-organize some stuff so this wouldn't happen...and then I forgot and moved the example scripts around anyway. Hopefully it doesn't cause too much confusion.
     
  23. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    I don't see any reason why this wouldn't be possible. I don't think I've heard of anyone doing peer-to-peer that falls back to dedicated server but I like the idea.
     
  24. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    This would only effect port forwarding and not punchthrough. You will often see this warning but then connecting will work just fine.

    Looking at the output you posted everything seems to be have gone correctly. My guess would be that the connection is never actually being made because you've overridden OnHolePunchedClient or OnHolePunchedServer without calling the base methods. I'll need more info to guess better. Are there are errors when it fails to connect? Does it timeout eventually? Did you test in the Example scene with unmodified NATHelper and ExampleNetworkManager?
     
  25. schicki01

    schicki01

    Joined:
    Jun 14, 2017
    Posts:
    8
    I use the example NetworkManager and the default Nat Helper script and I did not override any Method. Yes, I get a Timeout Error Log after a while. I dont get past "Attempt to connect through hole". I disabled "Connect Relay" and the rest is enabled. If enabled, connection via Relay works.

    Sometimes I get the Warning
    "NATTraversal: Received disconnect message on client for unrecognized connection."
    and once I got "Punchthrough failed" followed by "Unexpected raknet message received: ID_NAT_PUNCHTHROUGH_FAILED" but usually I just get the Timeout.

    Edit: I thought it may be the firewall, but connection via punchthrough only works when I run two instances on the same machine. The other machine with disabled firewall can´t get through.
     
    Last edited: Nov 19, 2017
  26. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    You should specifically test in the included Example scene that already has this set up. It seems like you're doing everything right but I could be forgetting something, so best to simplify things as much as possible and start from there.

    Are you connecting to the default facilitator at grabblesgame.com or hosting your own? If you're hosting your own where is it hosted?

    And you're totally sure the host machine doesn't have any kind of firewall on?

    Also check your router settings. If both the host and connecting client are set to use symmetric nat then punchthrough just isn't going to be possible and you'll need to either allow falling back to the relays or you'll need to change your router settings. Sadly punchthrough just isn't always possible so you should expect it to fail in some cases.
     
  27. schicki01

    schicki01

    Joined:
    Jun 14, 2017
    Posts:
    8
    For Starters I use the AWS service, but I also tried with the grabblesgame.com server, got the same Result.

    Yes I disabled all Firewalls.

    I assume this is the problem. However I have no means to clarify that on my end and I have to contact my provider.
    Thank you for your input, since the scripts seem to be working just fine, I´ll play around and see what I can do.
     
  28. daggada2

    daggada2

    Joined:
    Sep 8, 2015
    Posts:
    9
    Hi Zebadiah!

    So I'm trying to run Facilitator distributed with the Unity plugin on my VPS which has CentOS 6.9 running. I know your instructions say to update libstdc++ as I'm getting libc errors:
    ./Facilitator: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by ./Facilitator)
    ./Facilitator: /lib64/libc.so.6: version `GLIBC_2.15' not found (required by ./Facilitator)

    OS appears to be at libc 2.12. Is my only choice to update libstdc++? Not sure how easily I can do that, probably have to run down getting all the matching dependecies right? Don't happen to have an old build around do ya? Thanks for any help.
     
  29. Morderkaine

    Morderkaine

    Joined:
    Oct 22, 2016
    Posts:
    11
    Hi Zebadiah,
    I have tried to add host migration to my game and your NAT Traversal throws an error when a Network Migration Manager is added to the network manager.

    InvalidCastException: Cannot cast from source type to destination type.
    NATTraversal.NetworkManager.get_migrationManager ()
    NATTraversal.NetworkManager.StartHostAll (System.String matchName, UInt32 maxPlayers, Boolean advertise, System.String password, Int32 eloScore, Int32 requestDomain, Int32 directConnectPort, UnityEngine.Networking.Match.DataResponseDelegate`1 callback)
    ericNetworkManager.CreateHost () (at Assets/_Scripts/ericNetworkManager.cs:211)
    ericNetworkManager.OnGUI () (at Assets/_Scripts/ericNetworkManager.cs:223)

    Is there something special that needs to be done to have Nat traversal work with host migration?
     
  30. tyomklz

    tyomklz

    Joined:
    Jul 31, 2015
    Posts:
    48
    When it'll be supporting Android?
     
  31. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    I'll see if I can compile you a fresh one for CentOS 6.9 sometime later today or tomorrow. Unfortunately I didn't keep old releases back before I switched to newer GLIBC.
     
  32. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    You should use the "NAT Migration Manager" instead which is almost exactly the same as the "Network Migration Manager" with the only difference being that it is compatible with NAT Traversal.
     
    Morderkaine likes this.
  33. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    As of right now it looks like never, but mobile support is often requested so if that changes I will make sure to make a big bold post here and tag every user that has requested it.

    Also, I've said this before but it's been a while so I'll mention it again: NAT Punchthrough doesn't work on mobile networks. Even if I port NAT Traversal to mobile devices it will only be helpful on wifi not satellite connections.
     
  34. tyomklz

    tyomklz

    Joined:
    Jul 31, 2015
    Posts:
    48
    Well, the thing is that back in 2016 I've been using Unity's legacy networking and this, and got it working (I've been messaging you back then a long time ago because of this), though as you said I've been using Wi-Fi mobile connection. So, basically there are no other cheaper options at moment except using what Unity delivers from the box (their servers and etc)?

    P.S. thank you for the quick answer and for the tagging in advance :)
     
    Last edited: Nov 26, 2017
  35. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    @tyomklz Sorry I don't know of any other options for mobile (it's not really my area of expertise, I've hardly ever done anything on mobile).
     
  36. BillBucky

    BillBucky

    Joined:
    Nov 4, 2016
    Posts:
    7
    Hello,

    Just recently I have been getting these warnings which is not allowing my friend to connect to me. I can connect to him just fine as he is not getting these warnings. Any fixes for this issue?

    https://i.imgur.com/bHrsHoF.png

    Thanks!
     
  37. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    The IPv6 error is safe to ignore, it just means you don't have an IPv6 address.

    The port mapping error may mean the port is already mapped. If you set the logging level to 'developer' it will print out a list of all mapped ports after attempting to map so you can confirm if those ports are in the list.

    If your friend is not seeing the ipv6 warning then maybe the issue is that he supports ipv6 and you do not. That shouldn't be a problem but the ipv6 support is less tested so I may have messed something up.

    Or it could be something else entirely. If you can get me a full log from both host and client it would help me figure out where things are going wrong.
     
  38. Morderkaine

    Morderkaine

    Joined:
    Oct 22, 2016
    Posts:
    11
    Regarding Host Migration - have you had it successfully work in a project?
    I am using UNET with Relays turned off (because of Nat Traversal :) ) and while using the AdvancedMigrationManager in the plugins->Nat Traversal folder (as that was the closest thing I could find to NATMigrationManager, I assume that is what you meant?) prevents the error that was happening with Unity's base migration manager, when the host disconnects and the GUI pops up, selecting the 'find new host' button will select a host (one person will get the you are new host message the rest get the option to reconnect) , but when that host tries to 'start as host' it throws an error about BecomeHost not being active if I recall correctly. So the new host never successfully becomes a host.
     
  39. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    @Morderkaine Last I checked it was working at least. If you get me the full error log I can look more into it though.
     
  40. BillBucky

    BillBucky

    Joined:
    Nov 4, 2016
    Posts:
    7
    Regarding my issue, if you guys are getting the same error I checked my firewall rules and it was blocking my unity editor not allowing any connections. Hope this helps you guys!
     
    thegreatzebadiah likes this.
  41. GIRsMySpritAnimal

    GIRsMySpritAnimal

    Joined:
    Jan 13, 2017
    Posts:
    45
    Is this easy to integrate with Xbox One and were there any changes that are needed when switching from StandAlone and UWP?
    Also I'm on Unity 2017.2 will it be OK on it? I didn't see it under the list and I'm worried it won't work
     
  42. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    I think you will not need NAT Traversal for Xbox One as they have their own built in stuff. I don't believe the asset works with UWP. Someone at some point reported that it wasn't working and I haven't gotten around to figuring out why yet.

    I also haven't tested in 2017.2 yet but I'll do that now just to confirm. I suspect it's fine though since the networking stuff hasn't been changing much in the latest versions.
     
    GIRsMySpritAnimal likes this.
  43. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    Just finished testing in 2017.2 and it all seems to work fine.
     
    GIRsMySpritAnimal likes this.
  44. GIRsMySpritAnimal

    GIRsMySpritAnimal

    Joined:
    Jan 13, 2017
    Posts:
    45
    Thank you so much!
    Do I have to pay for relay servers for Xbox like I would for the standalone if I don't use punch through or the plugin?
    Also btw how long will the plug in be on sale for? I don't get paid until the end of the month?
     
  45. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    I believe the sale ends any minute now if it hasn't already.
     
  46. BillBucky

    BillBucky

    Joined:
    Nov 4, 2016
    Posts:
    7
    I sent you a private message.
     
  47. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    @BillBucky Sorry I'm not ignoring you, just busy. I'll try and respond tomorrow.
     
  48. BillBucky

    BillBucky

    Joined:
    Nov 4, 2016
    Posts:
    7
    That's fine
     
  49. windwolfx_23

    windwolfx_23

    Joined:
    Jan 15, 2015
    Posts:
    11
    hi, I can connect to your facilitator, but not mine, running on a ec2 windows instance,followed FAQ instruction regarding security group setting, still can't connect. is it only linux instance can connect? or region selection also matter?
     
  50. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    @windwolfx_23 region shouldn't matter, nor should the OS of the client. I think probably you haven't got the ports opened correctly. You could try also opening the TCP ports in the same way as the UDP ports.