Search Unity

  1. We've closed the job boards. If you're looking for work, or looking to hire check out Unity Connect. You can see more information here.
    Dismiss Notice
  2. We're running great holiday deals on subscriptions, swag and Asset Store packages! Take a peek at this blog for more information!
    Dismiss Notice
  3. Check out our Unite Austin 2017 YouTube playlist to catch up on what you missed. More videos coming soon.
    Dismiss Notice
  4. Unity 2017.2 is now released.
    Dismiss Notice
  5. The Unity Gear Store is here to help you look great at your next meetup, user group or conference. With all new Unity apparel, stickers and more!
    Dismiss Notice
  6. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  7. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice
  8. Unity 2017.3 beta is now available for download.
    Dismiss Notice

[RELEASED] Simple NAT Traversal for UNET - 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:
    549
    I've considered it.
     
  2. thegreatzebadiah

    thegreatzebadiah

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

    Jmangles

    Joined:
    Aug 1, 2015
    Posts:
    18
    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:
    549
    @Jmangles I'll need to see the error / stacktrace.
     
  5. Jmangles

    Jmangles

    Joined:
    Aug 1, 2015
    Posts:
    18
    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. ZackLeodrano

    ZackLeodrano

    Joined:
    Jul 11, 2013
    Posts:
    53
    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:
    549
    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:
    549
    @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:
    549
    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:
    549
    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!
     
    ScoobyNooby and ZackLeodrano like this.
  14. ScoobyNooby

    ScoobyNooby

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

    WaaghMan

    Joined:
    Jan 27, 2014
    Posts:
    151
    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. ZackLeodrano

    ZackLeodrano

    Joined:
    Jul 11, 2013
    Posts:
    53
    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:
    549

    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:
    549
    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:
    10
    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:
    3
    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".
    [​IMG]

    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)
    [​IMG]

    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:
    549
    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:
    549
    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:
    549
    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:
    3
    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 at 10:39 AM
  26. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    549
    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:
    3
    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:
    4
    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:
    8
    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?