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
  2. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    @erpatton @TiToMoskito
    I just sent you both a message regarding this, but the short answer is that I don't know.
     
  3. GuTyKa

    GuTyKa

    Joined:
    Sep 12, 2013
    Posts:
    4
    Have you tried running v1.54 on Unity version 5.6.2f1? I've tried both of the example scenes in an empty project but it completely freezes the Unity editor after hitting play. No log entry or anything, I have to force close the editor. Same after restarting the PC. Thanks for looking into this!
     
  4. GuTyKa

    GuTyKa

    Joined:
    Sep 12, 2013
    Posts:
    4
    Okay it seems that modifying the default Facilitator IP solves the freeze. But ran into another issue with the Facilitator itself as I'm trying to run it on an Amazon linux server but as the server has multiple interfaces I can't force the Facilitator to use the correct one. As I use an elastic IP the public IP address is not even associated to the interface so it would be great to give the actual public IP address and the interface to the Facilitator. Is this possible somehow? Thanks!
     
  5. GuTyKa

    GuTyKa

    Joined:
    Sep 12, 2013
    Posts:
    4
    I've created a new Amazon server, so the interface/IP problem is gone, but unfortunately it seems that the freeze has nothing to do with the Facilitator IP rather than the NatHelper. If it exists in the project then the editor freezes upon playing the project 9 times out of 10. Tried it with an empty project and with Unity 5.6.2f1 and 5.5.0p4 with the same results. Builds runs fine, without any problems. When it runs in the editor or as a standalone build, it drops a warning after a few seconds:

    NATHelper: NAT Device not found
    UnityEngine.Debug:LogWarning(Object)
    NATTraversal.NATHelper:Update()

    However running builds won't freeze, but have the same warning message in the log.
    Do you have any idea how to eliminate the freeze? Thanks!
     
  6. ToxicPlayer

    ToxicPlayer

    Joined:
    Jul 25, 2017
    Posts:
    1
    So, I wanted to get this out there but of course I had to sign in lol.
    First of all I can join servers with passwords for some reason.
    To help, try seeing the code for the Password server things.
    Next try doing the same thing as that except don't make it where you can only make it private.
    Then maybe the connection problem might be fixed, *I'm not sure*
    so yeah, I can only play private servers with passwords.
    Once I joined a server that the name was the password, it worked!
    Also, this is most likely not to work because I tried it and no one could join and my password was the name.
     
  7. Wriggler

    Wriggler

    Joined:
    Jun 7, 2013
    Posts:
    133
    Howdy,

    Thanks for the great asset. Quick question: I'm trying to add the NATHelper component at runtime, but encountering some issues. (The reason for me wanting to add at runtime is that we're supporting platforms that don't have NATTraversal support, so we want to exclude the asset on those platforms. Having NATHelper serialised into our scene or prefab is no good on those platforms).

    So I'm adding the component inside Awake(), like this:

    Code (CSharp):
    1. NATTraversal.NATHelper natHelper = gameObject.AddComponent<NATTraversal.NATHelper>();
    2.         natHelper.facilitatorIP = "url";
    3.         natHelper.facilitatorPort = 61111;
    4.         natHelper.facilitatorTimeOut = 30;
    5.         natHelper.portForwardingEnabled = true;
    6.         natHelper.portForwardingTimeOut = 30;
    7.         natHelper.punchthroughTimeout = 60;
    However, in NATTraversal.NetworkManager.Start() I'm being told that "NATTraversal: Required NATHelper component is missing! Add the NATHelper to the same game object as your NetworkManager." However, I've already added it. I guess the NATHelper must do something other than calling GetComponent() to check it's existence, right? It looks like whatever reference this guy needs isn't being set, as I also get a NullReferenceException when calling StartHostAll().

    How I can reliably add this component at runtime?

    Thanks for your help!

    Ben
     
  8. Wriggler

    Wriggler

    Joined:
    Jun 7, 2013
    Posts:
    133
    Ah, solved it. It wasn't anything to do with NATHelper, but rather the fact that I was using Awake(). The Unity NetworkManager base class doesn't make Awake() virtual, so I was calling it using reflection. Turns out that NATTraversal's version of NetworkManager *does* mark Awake() as virtual (so I need to call base.Awake()) and it also calls the Unity base class using reflection. All makes sense now.

    Thanks all!

    Ben
     
    thegreatzebadiah likes this.
  9. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    Yeah, you can use -i and -p to pass in ip and port. You can even pass in multiple comma separated IPs if you want.

    ./Facilitator -i 192.168.0.1,192.168.0.2 -p 12345
     
  10. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    This means the NATHelper can't find your router. Are you actually behind a router? If so you can try increasing the port forwarding timeout on the nat helper which will make it search longer before failing.
     
  11. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    I just added a ton more null checks and whatnot to that method. If it doesn't stop crashing in the next version I'd say it's time to contact the Open.NAT devs because I'm pretty much stumped.
     
  12. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    I just finished testing cloud build and it seems to work for me. The logs seem to indicate that you are missing the dlls and maybe other things from source control so the cloud build can't find them.
     
  13. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    I just finally got the new version submitted. Lots of good fixes including support for 2017.1
     
  14. FoxCastz

    FoxCastz

    Joined:
    Jun 18, 2015
    Posts:
    75
    Kinda new, just bought your plug in, pieced it together and adapted my old custom network scripts to use this, it seems close to working but I get this error:

    NATTraversal: Failed to create match. We'll still try and host but it doesn't look good.
    UnityEngine.Debug:LogError(Object)
    NATTraversal.NetworkManager:OnMatchCreate(Boolean, String, MatchInfo)
    UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
     
  15. FoxCastz

    FoxCastz

    Joined:
    Jun 18, 2015
    Posts:
    75
    Still trying to get this to work. I disabled using unity matchmaking services to get rid of the previous error and I am now trying to manually get the match lists and pass the match to the StartClientAll.. but I keep getting this error now:
    NullReferenceException: Object reference not set to an instance of an object
    NATTraversal.NetworkManager.StartClientAll (UnityEngine.Networking.Match.MatchInfoSnapshot match, UnityEngine.Networking.Match.DataResponseDelegate`1 callback, System.String matchPassword, Int32 eloScore, Int32 requestDomain, Boolean matchAlreadyJoined)
    CustomNetManager.JoinIP (UnityEngine.Networking.Match.MatchInfoSnapshot match, System.String pass) (at Assets/Resources/Scripts/CustomNetManager.cs:59)
    CustomNetworkHUD.JoinIP (Int32 index) (at Assets/Resources/Scripts/CustomNetworkHUD.cs:97)
    UnityEngine.Events.InvokableCall`1[System.Int32].Invoke (System.Object[] args) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:189)
    UnityEngine.Events.CachedInvokableCall`1[System.Int32].Invoke (System.Object[] args) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:309)
    UnityEngine.Events.InvokableCallList.Invoke (System.Object[] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:637)
    UnityEngine.Events.UnityEventBase.Invoke (System.Object[] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:773)
    UnityEngine.Events.UnityEvent.Invoke () (at C:/buildslave/unity/build/Runtime/Export/UnityEvent_0.cs:52)
    UnityEngine.UI.Button.Press () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:35)
    UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:44)
    UnityEngine.EventSystems.ExecuteEvents.Execute (IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:50)
    UnityEngine.EventSystems.ExecuteEvents.Execute[IPointerClickHandler] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.EventFunction`1 functor) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:261)
    UnityEngine.EventSystems.EventSystem:Update()
    and this is the code it points to as being null:
    Code (CSharp):
    1. public void JoinIP(MatchInfoSnapshot match,string password) {
    2.         StartClientAll(match,OnMatchJoined,password);
    3.     }
     
  16. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    @FoxCastz Check out the first couple sentences in the "How to Use" section of the docs.

    You can't use the built in matchmaking without hooking up to unity's online services. If you don't want to use unity's matchmaking you should be using the other version of StartClientAll():

    Code (CSharp):
    1. public void StartClientAll(string hostExternalIP, string hostInternalIP, int directConnectPort = 0, ulong hostGUID = 0, NetworkID matchID = NetworkID.Invalid, string hostExternalIPv6 = "", string hostInternalIPv6 = "", NetworkMatch.ResponseDelegate<JoinMatchResponse> joinMatchCallback = null, string matchPassword = "", int eloScore = 0, int requestDomain = 0, bool matchAlreadyJoined = false)
     
    Last edited: Aug 1, 2017
  17. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    Version 1.55 Released

    Mostly stability / bug fixes this time. I did add auto-retry for facilitator connections though!

    Changes include:
    • Added wrapping so nat traversal can be easily disabled with DISABLE_NAT_TRAVERSAL define.
    • Added automatic retry for facilitator connection.
    • Fix for things going wrong when nat device searching finishes the same frame it starts.
    • Fix for editor crashes when no nat device is found (whoops).
    • Fixed issue were macs would hang for about 5 seconds during raknet startup.
    • Fixed port forwarding timeout so it will maybe work more properly now.
    • Fixed an error thrown on clients when punchthrough is enabled but the host does not provide a guid.
    • Attempted fix for open.nat related crashes
    • Updated documentation.
    Thanks everyone!
     
    Last edited: Aug 1, 2017
  18. FoxCastz

    FoxCastz

    Joined:
    Jun 18, 2015
    Posts:
    75
    Well the issue with using the plain StartClientAll() is that there is nowhere to enter passwords for private matches.

    EDIT: I enabled unitys matchmaking services, but am keep relays disabled and its still not working.
     
    Last edited: Aug 1, 2017
  19. FoxCastz

    FoxCastz

    Joined:
    Jun 18, 2015
    Posts:
    75
    Code (CSharp):
    1. Custom Network Hud
    2.  
    3. public MatchInfoSnapshot[] matches = new MatchInfoSnapshot[10];
    4.  
    5. void ListMatches(bool success,string extendedInfo,List<MatchInfoSnapshot> matchList) {
    6.         for(int i = 0; i < 10;i++) {
    7.             if(i > matchList.Count-1)
    8.                 break;
    9.             matches[i] = matchList[i];
    10.         }
    11.         foreach(Transform button in serverButtons) {
    12.             button.gameObject.SetActive(false);
    13.         }
    14.         for(int i = 0; i < 10;i++) {
    15.             if(i > matches.Length-1)
    16.                 break;
    17.             serverButtons.GetChild(i).gameObject.SetActive(true);
    18.             serverButtons.GetChild(i).GetChild(0).GetComponent<Text>().text = "Match";
    19.             if(matches[i].isPrivate)
    20.                 serverButtons.GetChild(i).GetChild(1).GetComponent<RawImage>().enabled = true;
    21.             else
    22.                 serverButtons.GetChild(i).GetChild(1).GetComponent<RawImage>().enabled = false;
    23.         }
    24.     }
    25.  
    26. public void JoinIP(int index) {
    27.         NM.JoinIP(matches[index],password.text);
    28.     }
    Code (CSharp):
    1. Custom Network Manager
    2.  
    3. public void HostIP() {
    4.         StartHostAll(PlayerPrefs.GetString("Name"),10,true,"");
    5.     }
    6.     public void JoinIP(MatchInfoSnapshot match,string password) {
    7.         StartClientAll(match,null,password);
    8.     }
    9.     public override void OnMatchJoined(bool success,string extendedInfo,MatchInfo info) {
    10.         if(success)
    11.             hud.serverButtons.gameObject.SetActive(false);
    12.         //base.OnMatchJoined(success,extendedInfo,info);
    13.     }
     
  20. FoxCastz

    FoxCastz

    Joined:
    Jun 18, 2015
    Posts:
    75
    So what happens in the code above, is that it will (presumably) work for the host, but when I use a client it gets an error when the scene first loads up(seems harmless though) then when I refresh the matchlist, it (presumably) shows the match in the form of a single button(looking good), BUT whenever I click the match button which calls the hud JoinIP(int index), it goes through to the Net manager JoinIP(MatchInfoSnapshot match,string password) and gives me a null exception message for the variable match in the StartClientAll line.
     
  21. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    @FoxCastz

    What error do you get when the scene first loads up?

    You'll want that call to base.OnMatchJoined() that you have commented out, though that doesn't appear to be your problem.
     
  22. FoxCastz

    FoxCastz

    Joined:
    Jun 18, 2015
    Posts:
    75
    The error on start is:
    NullReferenceException: Object reference not set to an instance of an object
    CustomNetworkHUD.ListMatches () (at Assets/Resources/Scripts/CustomNetworkHUD.cs:94)
    CustomNetworkHUD.Start () (at Assets/Resources/Scripts/CustomNetworkHUD.cs:34)
    Seems to be coming from this function call:

    Code (CSharp):
    1. NM.matchMaker.ListMatches(0,1,filter.text,true,0,0,ListMatches);
     
  23. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    Something definitely seems funky. Can you send me your project to the support email on the asset store page if it's not too huge?
     
  24. FoxCastz

    FoxCastz

    Joined:
    Jun 18, 2015
    Posts:
    75
    I can't send the project for reasons, but are there specific parts of code you'd like to see?

    Edit: I will send you the two scripts that have anything to do with the connection process and a screenshot of the object containing the network scripts.

    Edit2: Sent.
     
    Last edited: Aug 1, 2017
  25. FoxCastz

    FoxCastz

    Joined:
    Jun 18, 2015
    Posts:
    75
    Any luck determining the cause of crash?
     
  26. FoxCastz

    FoxCastz

    Joined:
    Jun 18, 2015
    Posts:
    75
    I can't figure this plugin out..
     
  27. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    Hi again @FoxCastz, I'm looking through your code now. The first thing I noticed was the commented out call to base.OnClientSceneChanged(). You'll definitely want that call in there or things will surely go wrong. I'm not sure if there are other issues, still reading through it all, but that one jumped out at me immediately.
     
  28. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    @FoxCastz Also your HUD should really probably not be a NetworkBehaviour since that is going to cause it to be immediately disabled on scene load and not enabled on clients until they connect to the host.
     
  29. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    @FoxCastz Other than the stuff I mentioned your code seems correct. I obviously don't have any of your gui stuff but I was able to get it connecting by just having it join the first match it finds instead of using a button. I suspect the main issue is that your HUD was being treated as a network object and thus disabled on clients.
     
  30. FoxCastz

    FoxCastz

    Joined:
    Jun 18, 2015
    Posts:
    75
    Ok, I redid a bunch of stuff according to what you recommended, most of the errors don't show up, but it isn't finding the hosted match at all.

    Edit: Since I can't send the whole project, would you be able to view my screen to see how it isn't working?

    also I get this weird error now too:
    The same field name is serialized multiple times in the class or its parent class. This is not supported: Base(CustomNetManager) hud
     
  31. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    I would rename that variable, there's already a hud variable in the parent class that it is conflicting with.
     
  32. FoxCastz

    FoxCastz

    Joined:
    Jun 18, 2015
    Posts:
    75
    ahh, ok. want me to resend changes so we can figure out why the client cannot find the host match?

    Get this error while hosting:
    NATTraversal: Failed to create match. We'll still try and host but it doesn't look good.
    UnityEngine.Debug:LogError(Object)
    NATTraversal.NetworkManager:OnMatchCreate(Boolean, String, MatchInfo)
    UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
     
  33. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    Generally the only reason it will fail to create a match is because you're not hooked up to the online services. You are welcome to send me a new version though.
     
  34. FoxCastz

    FoxCastz

    Joined:
    Jun 18, 2015
    Posts:
    75
    Haha you were right, I completely forgot I started this project as a LAN project so never bothered activating the multiplayer services on unity.
     
    thegreatzebadiah likes this.
  35. FoxCastz

    FoxCastz

    Joined:
    Jun 18, 2015
    Posts:
    75
    Does List Matches not work with this plugin? I narrowed it down to the fact that the matchList being returned by unitys built in ListMatches seems to return an empty list even though I have the host instance successfully running.
     
  36. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    ListMatches should work just fine, if you take a look in the Example scene at the ExampleNetworkManager.cs you will see I'm using OnListMatches() there. I would really recommend testing with the Example scene and example scripts first before trying to branch out into your own stuff just to make sure everything is working as expected on your system.
     
  37. FoxCastz

    FoxCastz

    Joined:
    Jun 18, 2015
    Posts:
    75
    It appears that I got it working, thank you for the help!
    There is however on occasional issue of hosting a new match right after ending another match causing weird problems, it only happens once in a great while.
     
  38. FoxCastz

    FoxCastz

    Joined:
    Jun 18, 2015
    Posts:
    75
    Sorry to bug you again, I just noticed that theres no way to properly filter matches by name when using the plugin, when I call matches.name, I get things like localip|netip|some other ip|ipv6|etc.. but never the name of the match that you designate when the match is being created.

    StartHostAll(PlayerPrefs.GetString("Name")+"'s match",10,true,"");
     
  39. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    Wow, I can't believe I messed that up! I'll have it fixed in the next version. In the meantime I believe you can work around it by setting the NetworkManager's matchName before calling StartHostAll(). I just somehow lost the line that should be setting this.matchName = matchName in StartHostAll(). Whoops!
     
  40. FoxCastz

    FoxCastz

    Joined:
    Jun 18, 2015
    Posts:
    75
    No problem, developing is a pain in the ass, I feel ya.
     
  41. deliinteractive

    deliinteractive

    Joined:
    Oct 8, 2014
    Posts:
    25
    Howdy again!

    We've been using this plugin for our released game since February, and for the most part things have gone pretty well! I do have a few questions though about odd stuff I've seen pop up in testing recently.

    Recently I found in debug logs sent by players failing to connect that the relay servers had been picking them up, but UNet didn't seem to understand that a successful relay connection had been made. As such, no player object was made (which is set to automatic, just as in the Example scene), no networked scene objects were spawned, etc. This seems to be increasingly common with our players, and in the latest build of NATTraversal, is a 100% occurrence for us devs if we turn direct and punchthrough connections off completely. The correct match is found and joined, and I can even pull the match info out of the delegate used on successful match joining to confirm that the address corresponds to a known relay server address, with port 9999. If I continue to watch "relayClient" in the network manager, the reference is not null, but relayClient.connection IS null. We only use StartClientAll() and StartHostAll() functionality. If we use the Example scene with the same settings on the network manager, a relay connection is successfully made and the player objects are made on both ends. I have fiddled and toyed with everything in our network manager. Every method I did an override on, I always called the base implementation first. I pulled server IP binding out just to check if that was the problem. Still no luck on those relay connections. Does anybody have an idea what's going on here?

    Okay, next up, the facilitator seems to be returning unexpected messages more frequently now. I get a message pretty often, even when punchthrough succeeds, that the "NAT_Target" was "not connected". Other unexpected RakNet messages seem to show up pretty often as well, and overall, punchthrough success rates seem to be lower than usual in the recent month. Did the Facilitator program get updated since February and we just need to switch out the currently running one for the latest one?

    We're just about to release an update which is going to give us logging to an Azure server on our connection success rates, so I'll pop back in when I have the real numbers to see if they look normal.
     
  42. deliinteractive

    deliinteractive

    Joined:
    Oct 8, 2014
    Posts:
    25
    Problem solved with the relays!

    We had a delegates in StartHostAll() and StartClientAll() which were just for debug logging purposes, checking on the matchmaking. Turns out that there are other delegates which go in those arguments if you leave them null, and they are entirely necessary in keeping the match listed/joining over relay.
     
    thegreatzebadiah likes this.
  43. TubooBokBok

    TubooBokBok

    Joined:
    Mar 2, 2014
    Posts:
    30
    Hello.

    What is the appropriate way to disconnect from the game as a client and host?

    At the moment I am using the following code (located inside my NetworkManager script), which was taken from your example scene:


    Code (CSharp):
    1.     public void ShutdownServer() {
    2.         if (NetworkServer.active) {
    3.             NetworkServer.SetAllClientsNotReady();
    4.             StopHost();
    5.         }
    6.         else {
    7.             StopClient();
    8.         }
    9. SceneManager.LoadSceneAsync("MainMenu");
    10.     }
    When a client disconnects from a server, the client takes about a second to disappear on the host, and the host gives the following error:
    "ServerDisconnected due to error: Timeout"

    If the host disconnects while clients are still connected the following errors are displayed on the client(I hoped that all clients would be disconnected in the case of StopHost() being called):

    "Failed to send internal buffer channel:0 bytesToSend:25
    Send Error: WrongConnection channel:0 bytesToSend:25
    Failed to send internal buffer channel:1 bytesToSend:29
    Send Error: WrongConnection channel:1 bytesToSend:29
    ServerDisconnected due to error: Timeout"


    What is the correct way to properly disconnected a client and shutdown a server and disconnect all clients when the host disconnects?

    Thanks for your help.
     
  44. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    I believe the timeout disconnects are intentional due to an odd decision by the UNet team. The issue is that the disconnect message is queued but then the client is immediately shut down so it never goes out. I do something like this in my own code:

    Code (CSharp):
    1.  
    2.             if (NetworkServer.active)
    3.             {
    4.                 foreach (NetworkConnection con in NetworkServer.connections)
    5.                 {
    6.                     if (con != null && con.isConnected)
    7.                     {
    8.                         con.DisconnectConnection();
    9.                     }
    10.                 }
    11.                 yield return new WaitForSeconds(.02f);
    12.                 NetworkManager.instance.StopHost();
    13.             }
    14.             else
    15.             {
    16.                 if (NetworkManager.instance.directCon != null && NetworkManager.instance.directCon.isConnected)
    17.                 {
    18.                     NetworkManager.instance.directCon.Disconnect();
    19.                 }
    20.                 if (NetworkManager.instance.punchthroughCon != null && NetworkManager.instance.punchthroughCon.isConnected)
    21.                 {
    22.                     NetworkManager.instance.punchthroughCon.Disconnect();
    23.                 }
    24.                 if (NetworkManager.instance.relayCon != null && NetworkManager.instance.relayCon.isConnected)
    25.                 {
    26.                     NetworkManager.instance.relayCon.Disconnect();
    27.                 }
    28.  
    29.                 yield return new WaitForSeconds(.02f);
    30.                 NetworkManager.instance.StopClient();
    31.             }
    32.  
    Eventually I may work something like that in to the plugin but I'm wary to do so since the timeout disconnect behaviour is "intended"

    Here is the relevant thread about disconnecting: https://forum.unity3d.com/threads/u...outs-connection-instead-of-disconnect.466158/
     
    TubooBokBok likes this.
  45. TubooBokBok

    TubooBokBok

    Joined:
    Mar 2, 2014
    Posts:
    30
    On line 8 of your code you have "con.DisconnectConnection();".
    My NetworkConnection does not have the method DisconnectConnection(). Do you just mean con.Disconnect()?

    Thank you for your help.
     
  46. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    DisconnectConnection() is provided via an extension method. Make sure you're "using NATTraversal"
     
    TubooBokBok likes this.
  47. TubooBokBok

    TubooBokBok

    Joined:
    Mar 2, 2014
    Posts:
    30
    Hello,

    Sorry for posting so my questions!

    Is there any way to catch and handle messages returned from the NatHelper, such as "NAT Helper: ID_NAT_TARGET_UNRESPONSIVE" or "NATHelper: Unexpected raknet message received: ID_NAT_TARGET_NOT_CONNECTED"?

    I receive these messages when a client attempts to connect to a host that has since been shutdown.

    Also, I read in your documentation that "NAT punch-through works more often if you have at least two public IPs on the server your Facilitator is running on."
    I have no experience with servers. I am looking at renting a VPS from here: https://www.cheap-vps-hosting.co.uk/vps-hosting#full-comparison

    Their servers have a dedicated IP address, but would they be sufficient for hosting the facilitator? I see no mention of the number of public IPs they offer.

    Thank you very much for your help.
     
  48. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    You can try overriding OnHolePunchedClient and checking if success is false. I'm not totally sure that is called in all cases though.

    I wonder what it is you are trying to do to handle these messages though? Generally they are harmless, especially if you're receiving them when no longer listening for punchthrough.

    I believe pretty much any vps is going to be able to give you multiple IP addresses. You may have to contact them to request it and they may charge extra for it. It's not uncommon to get more than one for free though. I'm not familiar with cheap-vps-hosting, but if you email them I'm sure they can give you a concrete answer.
     
    TubooBokBok likes this.
  49. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    Hey NAT Traversal fans, we just released a new plugin that you may be interested in.

    It's called SmoothSync and it makes it super easy to smoothly sync transforms and rigidbodies over the network. No more choppy NetworkTransforms. It also significantly reduces the amount of bandwidth used to sync objects, once again saving you money on traffic over the relays (you know how I love to do that).

    Check it out and if you have any questions / comments leave 'em over at the forum post.

    Cheers,
    Zeb
     
    TubooBokBok likes this.
  50. bonkabonkstudios

    bonkabonkstudios

    Joined:
    Dec 24, 2014
    Posts:
    2
    Hi,
    I really love this product and has been a great time saver! But I seem to have run into a little bit of a problem when I disconnect from a host and then attempt to rejoin that same game. It won't allow the reconnection. I noticed this only happens when I use an online scene, it works fine if there is no switching of scenes. Any help would be greatly appreciated!