Search Unity

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

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

  1. windwolfx_23

    windwolfx_23

    Joined:
    Jan 15, 2015
    Posts:
    11
    I openned all ports, still failed, I sent you an Email about details < contact@noblewhale.com>
     
  2. Sorobaid

    Sorobaid

    Joined:
    Aug 31, 2012
    Posts:
    13
    Hi @thegreatzebadiah, I have bought your plugins nat traversal before and I just bought the matchup (good job on this!). My goal is to make a multiplayer P2P game so I need the hole punchthrough.
    So there are some things that still confuse me after I tested combining both of them:
    1. First my setup for two clients are: 1 PC (desktop), one running from Unity Editor and the other on the executable build (as host most of the time).
    2. I setup the matchmaker from Matchup plugin in a ubuntu server (as note: grabblesgame matchmaker is down for me at the time of this writing)
    3. If I run the Matchup example scene (normal unet), I can connect between both
    4. If I run the Nat Traversal using Unity match making, I can do hole punch (I only allow this mode for now). But sometimes the matchmaking will fail to list the match especially if I am not on the same Nat.
    5. If I run the Nat Traversal Match up example scene, I can't do hole punch at all. There is a warning: ID_NAT_TARGET_NOT_CONNECTED
    6. So, I combine the example from unity match making, remove the unity part, put the matchup logic. Now, they can connect. But there is no message if the punchthrough is succesful like in point 4
    [Edited}: ok. I can connect if I am using StartClient (I think unity default connect) but I will fail if I use StartClientAll with the same warning as point 5

    So, can you help me on this? I am confused if it actually connect via punchthrough or direct connection? (I debug log all relay, punchthrough, direct objects to check but all return null)

    7. And I also try to host the facilitator on the Ubuntu same as the matchmaker, but I can't connect to it (no error on server side, all port is opened)
    Thanks man and keep up the good work.
     
    Last edited: Jan 4, 2018
    RoyArtorius likes this.
  3. Domanxs

    Domanxs

    Joined:
    Jul 25, 2014
    Posts:
    76
    Just trying to be totally clear:

    If we use the matchmaker and use the match in the StartClientAll(match); it connects trough punch if direct cant work.
    But If we use Steam lobbies, and do StartClientAll(publicIP,internalIP); it never works unless direct connection is turned on, what are we doing wrong?
     
  4. RoyArtorius

    RoyArtorius

    Joined:
    Jul 11, 2013
    Posts:
    73
    I did an experiment to see what was wrong because I was having the same issue. Turns out that the guid being sent through the matchdata changes a bit when it is read by a client. I just compared the guid of the host to the guid of the client and they were not the same. This was fixed by just setting the guid in matchdata as a string using ToString and parsing it as ulong when trying to use it on the client; this seems to be working for me so far.
     
  5. TubooBokBok

    TubooBokBok

    Joined:
    Mar 2, 2014
    Posts:
    30
    Hi @thegreatzebadiah

    Do you have an example scene or any instructions on how to set up host migration?

    Currently I have simply added your "Advanced Migration Manager" to my network manager object.

    When the host disconnects I receive the error:
    "host id out of bound id {-1} max id should be greater 0 and less than {1}" on clients.

    Clicking the choose host and start as host buttons after this gives the following errors:
    "BecomeHost NetworkClient not active."
    "NetworkServer.BecomeHost failed"

    Thank you!
     
  6. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    I'm really not sure why it would be failing to connect other than something like a firewall. You're not trying to host the Facilitator on the same computer as a client or host are you?

    I'm looking into your other issues with the lobby. There seems to be something up with some of the newer versions of unity. I should have a fix ready to go in a day or so.
     
  7. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    Interesting. There have been a couple reports of this. I wonder if there is some issue with different servers handling / storing longs differently that is causing this. Worse case scenario I can switch everything over to being stored as strings and it probably wouldn't make that much of a difference...kind of lame though.
     
    RoyArtorius likes this.
  8. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    If you're not passing a guid into StartClientAll it can't do punchthrough. You'll need to store the host's guid in the lobby data or something similar so that the clients can read it and pass it in to StartClientAll
     
  9. Sorobaid

    Sorobaid

    Joined:
    Aug 31, 2012
    Posts:
    13
    Thanks man this actually the reason. At least now I can connect using punchtrough on my PC.

    Hi @thegreatzebadiah is there other requirement to do this? Now, I tried to hole punch using 2 PC: 1. desktop, 2. laptop with mobile data from my phone. Can I do this anyway? I also sometimes get NAT DEVICE NOT FOUND, does it mean I can't do hole punch if this happen?
    Now it fails with ID_NAT_PUNCHTHROUGH_FAILED message.

    And I also have the same problem with facilitator (I think). I am hosting it in the same server as the matchup server but I can't connect to it somehow.
     
    RoyArtorius likes this.
  10. Deleted User

    Deleted User

    Guest

    Hi @thegreatzebadiah
    I have a several issue since few month, Unity Editor or Standalone Player crash highly frequently at the first launch. (at the second launch it's ok but if you continue with many launch it crash again...)

    Apparently, this is a problem with the RakNet DLL. Do you have an idea to fix it?

    ========== OUTPUTING STACK TRACE ==================

    0x000000004241D171 (RakNet) RakNet::RakPeer::GetRemoteSystemIndex
    0x000000004241D33F (RakNet) RakNet::RakPeer::GetRemoteSystemFromSystemAddress
    0x0000000042426615 (RakNet) RakNet::RakPeer::CloseConnection
    0x0000000042428298 (RakNet) RakNet::RakPeer::RunUpdateCycle
    0x000000004241B86E (RakNet) RakNet::RakPeer::CallPluginCallbacks
    0x000000003B8B2FDF (MSVCR90) endthreadex
    0x000000003B8B3080 (MSVCR90) endthreadex
    0x00007FFC40932774 (KERNEL32) BaseThreadInitThunk
    0x00007FFC41170D51 (ntdll) RtlUserThreadStart

    ========== END OF STACKTRACE ===========

    If you want the full log, you can download it here : https://goldenpanic.missingnostudio.com/Editor-prev.log
     
  11. Kobaltic1

    Kobaltic1

    Joined:
    Jan 22, 2015
    Posts:
    183
    I am running Nat traversal and match up. I am running the match up example under nat traversal. First the network object is missing two scripts. I don't know which two they are supposed to be. So I put in examplematchup and nat helper. I get the following error when I run the program.
    Code (CSharp):
    1. NATHelper: Something went wrong mapping port 61600->61600 (Tcp)
    I get a random port. I have added it to my router but then I just get another random port. I am not using these port numbers so I am not sure where they are coming from. Here is a list of port numbers I got before I gave up.
    59800
    61925
    61396
    65535
     
  12. Sorobaid

    Sorobaid

    Joined:
    Aug 31, 2012
    Posts:
    13
    Any help can be provided? I have sent email to the support
     
  13. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    You can not do that sorry. Punchthrough doesn't really work with mobile networks.

    This will not prevent punchthrough from happening but it may interfere with port forwarding. I mostly tell people to ignore because in my experience it happens almost randomly but never prevents me from connecting. Let me know if you notice otherwise though.
    That would mean punchthrough isn't possible for whatever reason, probably because both client and host are behind symmetric nat.
    Did you ever resolve this issue? Who is your hosting provider? Make sure you're not behind any firewalls and that you've opened the ports mentioned in the FAQ if you're using AWS.
     
  14. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    Has you had the crash happen in other versions of the editor or just 2017.2.1p1?
    What other plugins are you using?
    You may have to send me your project, or even better a small example that recreates the issue. It's not happening to everyone so I assume it's either something specific to your project or specific to that version of the editor. I'll do some testing in that version but if I don't find anything I'll need some help from you to track it down.
     
  15. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    Sorry about that. I must have messed something up when packaging the plugin.

    Those were the correct scripts :)

    I believe this is the port that the Facilitator is being connected to on. It is random every time. You should not manually forward the port in your router. The automatic port forwarding should handle that for you. In your case though it appears that either your router does not support automatic port forwarding, or it is disabled in the router settings. This means connections are going to work less often than they should for you, but it doesn't necessarily mean a connection won't be possible.

    Do connections seem to work for you? If so it is safe to ignore that warning. If notice lots of failed connections you will probably want to consider enabling automatic port forwarding (sometimes called upnp or pnp) on your router (if possible).
     
  16. Kobaltic1

    Kobaltic1

    Joined:
    Jan 22, 2015
    Posts:
    183
    Ok that makes sense. Every once in a while I don't get the message. I do have uPnP enabled. I always get a connection on the facilitator. This leads me to my real issue. I do NOT have Unity match making enabled. I want to make sure I am using matchup and I get this error:

    upload_2018-1-18_7-27-3.png

    It never creates the match and I always get that NATTraversal error. In this case I did not get the error about the ports.
     
  17. Sorobaid

    Sorobaid

    Joined:
    Aug 31, 2012
    Posts:
    13
    [EDITED]After I check, my PC is behind a Port Restricted Cone NAT. Is there any other nat beside symmetric nat that this could fail. Is there any way to check what actually cause the punchthrough fail?

    I host it in digital ocean. As far as I know I should have opened all port (1-65535) but I still can't connect on it. There is no error message whatsoever too.
    putty.jpg
     
    Last edited: Jan 19, 2018
  18. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    This is because you have Connect Relay enabled. Relay connections depend on Unity's matchmaking. Just uncheck that check box and you should be good to go.
     
  19. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    I haven't been able to replicate this in 2017.2.1p1

    Do you get the issue when testing in a fresh project? Anything you can do to try and narrow down the cause would help me track it down.
     
  20. Kobaltic1

    Kobaltic1

    Joined:
    Jan 22, 2015
    Posts:
    183
    Thanks, I got rid of the error now with unchecking that box. I assume when I go into production I want to check that again and have it fall back to the Unity relay servers???? I still don't have a match. It seems this code doesn't create the match for some reason. Line 130 in ExampleMatchUp.
    Code (CSharp):
    1. this.CreateMatch(netManager.maxConnections + 1, matchData);
     
  21. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    Yeah, it's pretty much that or accept that some small percent of players will not be able to connect to each other. You'll just need to make sure to hook your project up to Unity's multiplayer services so that you can actually create matches.

    Are you getting any kind of error message or is the match just missing from the match list? If you're using any filters try removing them to make sure you're not accidentally filtering the match out. If you're running your own Match Up Server you can also use the -v flag to get verbose output which will allow you to see when matches are created on the server.
     
  22. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    Check out the success graph on this page: http://www.raknet.net/raknet/manual/natpunchthrough.html
    As far as I know there is no way to get more info. You will see different messages for different errors. Generally ID_NAT_PUNCHTHROUGH_FAILED means punchthrough simply isn't possible.

    I'm trying to get to the bottom of this but honestly I'm pretty stumped. I'm positive there are other users hosting the Facilitator on digital ocean servers, and the Facilitator itself hasn't changed in almost 2 years (I just checked, man how time flies). You can try using the -i option when you start the Facilitator to pass in a specific ip for it to host on. Double check the ip you are connecting to in the plugin and maybe try using your server's public dns if that's a thing.
     
  23. Kobaltic1

    Kobaltic1

    Joined:
    Jan 22, 2015
    Posts:
    183
    The match is missing from the list. Also the debug message "match created" is blank. I am running the default ExampleMatchUp straight into an empty project. I have not changed anything.
     
  24. WongKit

    WongKit

    Joined:
    Apr 27, 2017
    Posts:
    26
    Hi,

    I am quite new to Unity, so maybe I am doing something wrong, but I think your method StopHost() also kills other server connections that are not related to matchmaking. I am running an additional NetworkServerSimple instance which starts throwing
    as soon as the StopHost() Method is called.

    To reproduce this, I just used the included ExampleNetworkManager Script and the CustomServer.cs below.
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Networking;
    3.  
    4. public class CustomServer : MonoBehaviour {
    5.  
    6.     private NetworkServerSimple networkServer;
    7.  
    8.     private void Start() {
    9.         networkServer = new NetworkServerSimple();
    10.         networkServer.Listen(23451);
    11.     }
    12.  
    13.     void Update() {
    14.         if (networkServer != null) {
    15.             networkServer.Update(); //host id out of bound id... here
    16.         }
    17.     }
    18. }
    I do not get the errors when using Unity's build in Network Manager.
     
  25. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    @WongKit You're totally right. I got a bit sloppy there. It should be fixed in next release. If you'd like to test out the latest release before it hits the store (and confirm for me that it actually fixes your issue) send me a message at the support email and let me know which version of Unity you are running.
     
    WongKit likes this.
  26. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    Sorry for not responding for so long. I've found some bugs in the host migration and general disconnecting stuff that I'm still working through.
     
  27. WongKit

    WongKit

    Joined:
    Apr 27, 2017
    Posts:
    26
  28. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    @TubooBokBok I believe I've fixed the issues with host migration. If you email me at the support email or direct message me here I can send you the latest build to test.
     
    Kobaltic1 likes this.
  29. Kobaltic1

    Kobaltic1

    Joined:
    Jan 22, 2015
    Posts:
    183
    I got the example working. In the console the debug doesn't state the match name when the server creates it or when the client connects to it.

    I went back to my own project. The issue I have now is that the match is created before I connect to the facilitator. I am trying to figure out what starts the connection to the facilitator so I can call that before the player sets the match information.
     
  30. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    @Kobaltic the Start() method of the NetworkManager initiates the connection to the Facilitator (as long as you have Auto Connect To Facilitator checked). It's an asynchronous process though so what you probably want to do is wait for natHelper.isConnectedToFacilitator or natHelper.hasFailedToConnectToFacilitator to be set to true.
     
  31. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    I just submitted the latest version. Should be on the store in a few days or so. It's full of fixes for the lobby and host migration as well as some new example scenes.
     
  32. Kobaltic1

    Kobaltic1

    Joined:
    Jan 22, 2015
    Posts:
    183
    Thanks for all your help. I have this working now. And not connected to Unity.
     
    thegreatzebadiah likes this.
  33. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    NAT Traversal 1.58 Released
    • Added lobby example scene.
    • Added host migration example scene.
    • Improved Match Up example scene.
    • Fixed some issues with NATLobbyManager and NATNetworkManagerHUD that were preventing hosting from the lobby.
    • Fixed broken script assignments in Match Up example scene.
    • Changed how NetworkMatch component gets added.
    • Fixed issue with null client during host migration.
    • Fixed issues with disconnect message not getting sent. F
    • ixed host migration methods not being called.
    • Added README files for all examples.
    So much in this release! Thanks to everyone who reported errors and helped me work out solutions. Let me know if there are any issues with the new release.
     
  34. chadfranklin47

    chadfranklin47

    Joined:
    Aug 11, 2015
    Posts:
    229
    In this new update you seemed to have messed up the NATLobbyManager. I can't properly set the Lobby Scene and the Play Scene.
     
  35. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    I just emailed you. I can't be sure but my guess would be you just haven't added the lobby and play scenes to your build settings.
     
  36. golergka

    golergka

    Joined:
    Mar 15, 2012
    Posts:
    30
    Thanks for your plugin! It's been an enormous help.

    However, I'm running into problems with my current project. Right now, we're running a custom solution, only partially based on HLAPI (and we're planning to move to low-level tranport API in near future), so I can't use MultiplayerManager or any subclass of it.

    I was trying to do the punch through using NATHelper, and your original version on github was very helpful - however, I see that I can no longer get internal and external IP address from it. What's the current way of getting this information? It would be great if you included some kind of tutorial of using this plugin with the low-level transport API as well.
     
  37. golergka

    golergka

    Joined:
    Mar 15, 2012
    Posts:
    30
    So far, I managed to get a successful puncthrough response on the client. However, after punchthrough happens, it seems that your plugin is still occupying the socket. I'm doing basically this:

    m_Client = new NetworkClient();
    m_Client.hostPort = ClientPort;
    m_Client.Connect(ServerAddress, ServerPort);

    and I get this error:

    Cannot open socket on ip {*} and port {57400}; check please your network, most probably port has been already occupied

    where 57400 is client port that I got from punchthrough callback. Is it a bug or am I using the plugin incorrectly?
     
  38. Sorobaid

    Sorobaid

    Joined:
    Aug 31, 2012
    Posts:
    13
    @thegreatzebadiah. Continuing from our discussion on the facilitator. This is the stat from my server facilitator.png
    The port is all opened. And this is the Unity setting facilitator-setting.png
    The error is only because I turn off the matchmaking server. Is my setup correct for the facilitator?
     
  39. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    @Sorobaid it looks like the Facilitator is hosting on the wrong IP. You can try and force it to use the correct one using the -i flag:

    ./Facilitator -i 139.59.239.175
     
  40. Sorobaid

    Sorobaid

    Joined:
    Aug 31, 2012
    Posts:
    13
    @thegreatzebadiah Is it because the started on 10.15.0.5 ? I try running the command but still same result still-failed.jpg
     
    Last edited: Feb 6, 2018
  41. chadfranklin47

    chadfranklin47

    Joined:
    Aug 11, 2015
    Posts:
    229
    Do you know why when I host a match, then I connect to the host from a client with NATLobbyManager, then start the game, the game changes scenes, then I disconnect the client, then the host, then when I try to repeat that process I get this?:

    Code (CSharp):
    1. NATTraversal: Attempting to connect directly: ("My IPv6")
    2. UnityEngine.Debug:Log(Object)
    3. NATTraversal.NetworkManager:directConnect(String, String, String, String)
    4. NATTraversal.NetworkManager:StartClientAll(String, String, Int32, UInt64, NetworkID, String, String, DataResponseDelegate`1, String, Int32, Int32)
    5. CustomMatchmaker:OnJoinMatch(Boolean, Match) (at Assets/MyAssets/Scripts/Game/Multiplayer/CustomMatchmaker.cs:402)
    6. MatchUp.Matchmaker:OnJoinMatchInternal(Boolean, String, Match, Action`2) (at Assets/Plugins/Match Up/Matchmaker.cs:410)
    7. MatchUp.<JoinMatch>c__AnonStorey5:<>m__0(Boolean, String) (at Assets/Plugins/Match Up/Matchmaker.cs:288)
    8. MatchUp.<SendCommandAsync>c__Iterator0:MoveNext() (at Assets/Plugins/Match Up/Matchmaker.cs:519)
    Do I have to destroy the lobbymanager on disconnect or something?

    As of now, I can only reconnect by destroying the NATLobbyManager upon reload of the scene.

    Also, can you still not find why my matches aren't getting destroyed? Is there something I could be doing incorrectly? I tried to follow the ExampleMatchUp script as closely as possible. Maybe the Match up is conflicting with the lobbManager. Idk.
     
    Last edited: Feb 2, 2018
  42. roger-ramos

    roger-ramos

    Joined:
    May 16, 2015
    Posts:
    3
    Hello, I bought this plugin a month ago, I am a big fan of your Plugins I have them all (SmoothSync, Match Up and NAT Traversal). I have two VP Servers for testing now, (The Facilitator and Matchmaking Server are running in one of them) on the other one I got the GameServer, both running on ubuntu 16.04.02 LT. I ran a test with the GameServer On Windows Build and is connecting and everything looks to be okay, but when I run the HeadLess version of the GameServer I am getting this error, some clues of any ideas are welcome, i could be missing something.

    Thank you.
    Roger.
     

    Attached Files:

    Last edited: Feb 11, 2018
  43. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    Yeah, that's the issue but I'm not really sure why. You're either running a really old version of the Facilitator or something else funky is going on. It seems to be completely ignoring the ip you are passing in, and for some reason your port is 0...Are you using the Facilitator that is included with the plugin or did you download it from the top of this forum post? Or maybe you got it from an old version of the plugin and never updated?
     
  44. Sorobaid

    Sorobaid

    Joined:
    Aug 31, 2012
    Posts:
    13
    Hi, I use the one included in the asset store inside the plugin folder. Can you help me with this? I also try to get the ipaddress using
     
  45. RayKatz

    RayKatz

    Joined:
    Oct 18, 2013
    Posts:
    13
    Is a linux facilitator for 32bit planned?
     
  46. roger-ramos

    roger-ramos

    Joined:
    May 16, 2015
    Posts:
    3

    Hello thegreatZebadiah,
    Did you were able to replicate the error shown on my Image?, I am using NATLobbyManager, I ran a test with your LobbyExample and i am getting the same error (Not Handled exception). All the ports are open UDP for Facilitator and TCP for the matchmaking server. This Unhandled exception is breaking the GameServer execution.

    Thank you.
    Roger
     
  47. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    If you're working from the github code it's basically just old, unfinished, and broken. The actual plugin code should be more functional and there is a NAT Helper example included. You are correct though that the issue is that the RakNet connection needs to be closed before you can connect over the punched hole. I'm guessing the github code is from before I figured that out.
     
  48. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    This may be fixed in the latest release of match up. I'm not entirely sure if it's the same issue but it turns out matches could stick around if the Match Up server was shut down or crashed while matches were active. When it booted back up the matches would still be in the list but could never be destroyed.

    Are you still experiencing issues with the lobby as well?
     
  49. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    Really not sure what the deal with the exception is. Usually "NAT Device Not Found" is just a warning and not anything that should cause a crash. My best guess is something about the System.Threading library does not like being run in headless mode, or something about headless mode changes how exceptions are handled. The call to DiscoverDeviceAsync() is already wrapped in a try {} catch {} so I'm honestly not sure how that exception is getting thrown.

    I'm honestly confused as to why you're using NAT Traversal at all though if you're running a game server. Generally the reason NAT Traversal is needed is so that clients can connect to each other. If clients are only connecting to a game server that you control and not hosting their own games then NAT Traversal shouldn't really be necessary. You just need to make sure to open whatever ports your game server uses and set up any necessary port forwarding if your game server is behind a router.
     
  50. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    Not really, I haven't touched the Facilitator code or had to compile it in years now (yay stability). If I do find myself compiling the Facilitator again at some point though I'll make sure to make a 32bit version.