Search Unity

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

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

  1. gabmedalv

    gabmedalv

    Joined:
    Sep 21, 2015
    Posts:
    6
    Hello again

    We have now some questions about the integration with STEAM (Steamworks). In a multiplayer game, and different networks, we can only join to our custom network lobby using the NAT facilitator (the test facilitator), do you know if there’s a way to use the steam lobby instead of the facilitator?
    We've been trying direct connection but if we don't use facilitator the guid = 0. How does the guid works using the steam lobby?

    Thanks in advance.
     
  2. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    You can not use the steam lobbies in place of the Facilitator. You can use steam lobbies in place of Matchmaking, but you would still want to use the Facilitator for punch-through to work.
     
  3. Meneu

    Meneu

    Joined:
    Apr 21, 2015
    Posts:
    9
    @thegreatzebadiah
    hi there, is that any function that to make a network prompt window while application start if neccessery?
    right now it only prompt while the server side receive a onHolePunchedServer callback.

    thanks~

    :(
     
    Last edited: Apr 19, 2017
  4. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    @Meneu I think you're going to have to try that one again. I'm really not sure what you're asking. Maybe try to throw in some screenshots or code.
     
  5. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    NAT Traversal 1.52 Released
    • Matches are now finally destroyed immediately in 5.4+
    • Moved portmapping callbacks to the main thread to prevent crashing
    • Fixed some backwards compatibility issues with 5.2 and 5.3
    • Added missing tags to Debug.Logs
    • Added a new NATNetworkManagerHUD that works more correctly with the plugin.
    • Added try/catch to swallow exceptions when fetching external IP*
    • Exciting new logo and screenshots that are slightly more up to date
    Mostly stability and minor fixes. Nothing life changing. As always thanks everyone for reporting issues and working with me to get them fixed.

    P.S. Don't forget to rate / review the asset if you haven't already: http://u3d.as/qhh. The visibility bump it gives us really helps, especially right now while we're on sale :D

    * This is not actually fixed but will be in the next release. Message me if you get errors about WWW already being disposed and need a work around.
     
  6. lasha81

    lasha81

    Joined:
    Oct 3, 2016
    Posts:
    1
    Hello. in your example scene when player hosts the game sometimes for other players who wants to join, match list is empty. What can be the problem ? I've tested it on two different devices but the problem is same.
     
  7. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    @lasha81 what version of editor and plugin? Do you get any errors on host or client? It sounds like the WWW dispose bug but you should see an error if that is the case.
     
  8. martaaay

    martaaay

    Joined:
    Apr 13, 2009
    Posts:
    136
    I'm struggling through getting this all up and running. Does anybody by any chance have a reference implementation for having different kinds of playerPrefabs and different options for online scene? I feel i'm really close, but that I'm missing a step.
     
  9. Meneu

    Meneu

    Joined:
    Apr 21, 2015
    Posts:
    9
  10. mightybob

    mightybob

    Joined:
    Mar 23, 2014
    Posts:
    75
    Is the "default" facilitator used for testing no longer up and running? Nothing has changed in my project since yesterday, yet it will no longer connect to the facilitator. (when it would yesterday)
     
  11. mightybob

    mightybob

    Joined:
    Mar 23, 2014
    Posts:
    75
    Also, I got a question about the facilitator. Sorry if this is a really stupid question as I have very little knowledge about this sort of thing, but I have a website hosted by GoDaddy, would the facilitator run on that?
     
  12. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    I don't think there's anything in the plugin or unity to intentionally bring that window up. That is controller by the operating system when it detects a new networked executable running, as far as I know at least.
     
  13. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    Yes, it was down, it's up again now. As always I'd like to take this moment to remind everyone that the default Facilitator is just for testing, and if you don't want it to go down, you really need to host your own :)
     
    mightybob likes this.
  14. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    Probably maybe. There are a couple of requirements. You have to be able to get the Facilitator on to your server, usually via ftp or similar. You need shell access to the server to run the Facilitator. And you need to be able to unblock some ports for the Facilitator to use, if GoDaddy happens to be blocking them. I know AWS is super restrictive by default so you have to change some settings to open the ports but I'm not familiar with GoDaddy. They may not block anything by default, or it could be super restricted with no way to open the ports, or it could be just like AWS where you just need to change some settings.

    The best way to find out is to try and see if you run into any problems. There is a download link for the Facilitator at the top of this forum post, so you don't even need to buy the asset before you make sure you can run the Facilitator :)

    [edit] Here are the links to save you some clicks:
     
    mightybob likes this.
  15. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    As a rule of thumb, there should be very little difference between how you do things with the plugin and how you do things with regular old UNet, so when in doubt remove the plugin from the equations and see if you can get it working that way. If you can get it working without the plugin, and then adding the plugin overly complicates or breaks things...well that's probably a bug or design flaw in the plugin so let me know.

    If you're just looking for general advice on multiple player prefabs and multiple online scenes I suggest the unity discord: https://discord.gg/ExYh5JJ
     
  16. mightybob

    mightybob

    Joined:
    Mar 23, 2014
    Posts:
    75
    Ah ok, thanks. And yeah, of course, I will definitely get that Facilitator setup at some point, though I'm still in the very early testing stages :)

    Thanks a lot, great info.
     
  17. gabmedalv

    gabmedalv

    Joined:
    Sep 21, 2015
    Posts:
    6
    Hello again and thanks for your previous answers.
    We are really stucked in one problem.

    After configuring properly the facilitator, we are able to play in two different networks, but only in the unity editor.
    When we try again using generated builds, it doesn't work ... Host is created ok, connection info is registered on steam lobby (via steamworks), but the client simply can’t connect the lobby.
    It's weird, because using generated builds in the same network, everything works fine.

    Do you have any idea about this? Do we need to consider something before generating builds?

    We use Unity personal edition and only register the networking service without paying.

    Thanks in advance.
     
  18. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    @gabmedalv I can't think of anything in particular. It should all work the same in build as in editor. Do you get any errors in the logs? How does the connection failure happen, is it a timeout?
     
  19. gabmedalv

    gabmedalv

    Joined:
    Sep 21, 2015
    Posts:
    6
    We can’t see NAT logs in the build but the last of our logs says "Connecting ...", no error. It looks like a timeout error.
    The attached image shows our network manager flags, may be you can see something strange or wrong.

    img01.png img02.png

    Thanks again
     
  20. RoyArtorius

    RoyArtorius

    Joined:
    Jul 11, 2013
    Posts:
    73
    Hi all,

    I just got this asset and have been trying to get it to work. While I've been able to connect locally on my own computer, I can't connect to another computer's match. The computer is my friend's and in Europe. When he hosts, it appears listed as a CCU in the Unity services chart but when I try connecting, I get a message saying "Match list is empty" Am I missing a step or something? I don't have much experience with networking, but that's why I'm trying to learn what I'm doing wrong. Also when I first imported the asset, the text fields in the example scene were filled with just numbers, resetting the components seemed to fix that. Thanks and sorry for my noobness.
     
  21. RoyArtorius

    RoyArtorius

    Joined:
    Jul 11, 2013
    Posts:
    73
    Nevermind, I was able to figure it out. I just used the Advance Network Manager instead
     
  22. WaaghMan

    WaaghMan

    Joined:
    Jan 27, 2014
    Posts:
    245
    If you are in different continents, you're probably connecting to different Unity matchmaking servers and that's why the Unity match list is empty.
     
    thegreatzebadiah likes this.
  23. RoyArtorius

    RoyArtorius

    Joined:
    Jul 11, 2013
    Posts:
    73
    Hmm... that's probably what the problem was then. When I switched the manager I also had someone else in the US helping me test. I wonder if that would be a problem if we tried connecting using the other connect method where we just give the other person the external ip, internal ip, and guid.
     
  24. WaaghMan

    WaaghMan

    Joined:
    Jan 27, 2014
    Posts:
    245
    Should not be. The only problem would be that relay connections couldn't be established, but if you have the IP, direct connection / NAT will be able to be established.

    What we did regarding this issue is store the actual Unity matchmaking server address in the Steam lobby data (I think the code is a few pages back in this very thread)
     
    thegreatzebadiah likes this.
  25. RoyArtorius

    RoyArtorius

    Joined:
    Jul 11, 2013
    Posts:
    73
    I do have another question. One of my friends had the issue where NAT punchthrough failed, so we tried again with Use Relays on. What I saw in the console was that it did the initial punchthrough but at some point it did a second punchthrough attempt. Not sure if I misread or the console hadn't cleared or something, but I am curious as to what happens after a connection is established through the relay servers. Does it use that connection to establish a more direct connection or does it continue only using the relay servers which is what ends up costing money through bandwidth usage?
     
  26. HenkeBenkes

    HenkeBenkes

    Joined:
    Sep 15, 2015
    Posts:
    11
    I noticed that you added "Added catch/try when fetching...." on the new release note but I still get this error:
    NullReferenceException: WWW class has already been disposed.



    Am I doing something wrong here?
     
  27. bubbabruce

    bubbabruce

    Joined:
    May 23, 2014
    Posts:
    16
    Hi, I just bought and downloaded NAT traversal yesterday so I am pretty sure I have the latest one and I am getting the same error that HenkeBenkes is getting. The server is successfully started and the client sees the server and it appears to connect correctly (the callback that I pass into StartClientAll() gets called and the success parameter is true). After that happens I get the NullReferenceException: WWW class has already been disposed. This exception happens in NATTraversal.NetworkManager.handleExternalIPResponse. Thanks for any help you can provide.

    Kevin
     
  28. bubbabruce

    bubbabruce

    Joined:
    May 23, 2014
    Posts:
    16
    Actually there is something weird with the version on the asset store. I downloaded it and the asset stores says I have downloaded 1.52 but when I look at the README.md it says 1.51
     
  29. bubbabruce

    bubbabruce

    Joined:
    May 23, 2014
    Posts:
    16
    Even if I delete the NAT Traversal.unitypackage, delete the NAT Traversal plugin code from my project, re-download and re-import it still says 1.51 in the Readme.md. The data modified for all the files are 4/16.
     
  30. TimBurnstone

    TimBurnstone

    Joined:
    Nov 16, 2012
    Posts:
    9
    Just purchased today and followed your documentation here: http://grabblesgame.com/nat-traversal/docs/ , but I can't connect via a client build, using the example scene.

    In addition to the error listed above, im also getting the following 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)
     
    Last edited: Apr 26, 2017
  31. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    Hi all, I had my head down doing some work for a few days, but I'm responding to everything now. Sorry for the delay!
     
  32. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    Sorry for leaving you hanging on this. I don't see anything obviously wrong in your settings. Why can't you get the logs from the build though? They should be in the _Data folder right next to the executable.

    I think your best bet is to email me your project (stripped down as much as possible please) so I can take a look. You can send it to the support email on the asset store page. Also try testing in the Example scene with unmodified ExampleNetworkManager. If the example scene works it's either something in your code throwing it off or you're doing something I did not anticipate.
     
  33. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    You were likely just mistaken on your reading of the output. There is no second punch-through attempt. Once a client connects via relay they stay connected via relay. Unfortunately a direct / punchthrough connection just isn't possible or the relay connection would have never been used to begin with.
     
  34. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    No, I am. I messed up the fix. Email my at the support email for a new working build, or if you're patient you can wait for the next update to hit the asset store, but I haven't even submitted it yet so it will be a while.
     
  35. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    Yeah, this is a known unity bug, and I'm really not sure what to do it fix it and force unity to download the correct version. I do know that everyone has eventually gotten it to work somehow..If all else fails email me and I'll get you the correct version directly. You probably want to do that anyway actually since even if you were getting the latest version on the store...it does not have the WWW fix you're looking for. Email me, I'll sort you out.
     
  36. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    It sounds like you have not connected your editor to Unity's online services. Hit up the Services tab and make sure you've got the multiplayer services hooked up.
     
  37. icewiski

    icewiski

    Joined:
    Feb 25, 2017
    Posts:
    7
    how is this asset worked on Android ? and ios?
     
  38. sammyben

    sammyben

    Joined:
    Nov 12, 2013
    Posts:
    7
    Could please help me with a few issues we are having with your NAT Traversal plugin in Unity. When connecting to a match we keep encountering errors such as 'Host only supports ipv4 connections and client does not support ipv4' and 'Host only supports ipv6 connections and client does not support ipv4'. These occur both on a local network and from outside connections. Another thing that I have noticed is that the IPV6 lookup site (http://ipv6.icanhazip.com) does not seem to work in a web browser so I get an error message when I start my game saying that it was unable to get my ipv6 address, wondered if this could be affecting the connections?
     
  39. Meneu

    Meneu

    Joined:
    Apr 21, 2015
    Posts:
    9
    @thegreatzebadiah
    hi again, the plugin's Raknet.dll reported by antivirus and auto removed by default.
    any quick fix for this ?
     
  40. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    Only desktop platforms are officially supported. Windows, OSX, Linux.
     
    Last edited: Jun 28, 2017
  41. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    Well one possibility is that you are actually trying to connect from an ipv6 only network to an ipv4 only network, which just isn't possible, but that seems pretty unlikely. Are you getting these errors when testing with the Example scene and ExampleNetworkManager?

    This is normal if either your network adapter, router, or isp does not support ipv6. The error in the console is probably a little unnecessarily scary, but by itself not being able to fetch the ipv6 address shouldn't hurt anything. It just means you can't connect to ipv6 only networks, and no one will be able to connect to you via ipv6. Generally this is not a problem though since almost all networks support ipv4 either by itself or as part of a dual stack with ipv6.
     
  42. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    This is the first I've heard of this. It's probably a false positive. I'm not sure what I could be doing to set off an antivirus though. Does it offer any details or hints about why it thinks the dlls are malicious? Also what brand of antivirus do you use?

    The quick fix is probably to tell your antivirus to ignore that particular file, which there is usually some mechanism for doing. Obviously you'll have to make the call if you consider that safe to do or not. I can't really tell you "go ahead, it's all cool" because for all I know the dll really is infected. Maybe it got infected after you downloaded it, or Unity's servers are infected, or RakNet's github where I get the code from. The only piece I can personally vouch for is my own computer which is protected and appears to be clean as of the latest scan I just did.
     
  43. Meneu

    Meneu

    Joined:
    Apr 21, 2015
    Posts:
    9
    @thegreatzebadiah northon report that while it unzip the pack. and we distribute our pack with .zip
    is that a problem @@?
     
  44. dragonslaya84

    dragonslaya84

    Joined:
    Aug 10, 2014
    Posts:
    4
    Im new to unet and nat traversal, so im sorry if im doing something wrong. But once i start hosting using one of the pcs in my house i then i do startclientall(). Once i finish that i then try to send a message to server using NetworkManager.instance.client.send, but client on the non hosting computer side is always null.

    Is NetworkManager.Instance.client suppose to be only used on the hosters side? Or is it suppose to be used on client and hosters side? If it is suppose to be null on the clients side where would i get the info to send to server of the clients connection on the client computer? Would it be from one of the 3 directCon relayCon or punchThroughCon network client variables?

    btw NetworkManager.Instance is correct for me because i have my own instance class i use on top of network manager in class someone says the syntc is wrong and suppose to be singleton. Any help would be appreciated.
     
  45. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    I don't think zipping would cause any issues.
     
  46. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    @dragonslaya84 client should be set on the clients. I'd have to see some code to figure out why it's not. Try testing in the Example scene with the ExampleNetworkManager. If client is not null there it must be something in your custom network manager throwing it off.
     
  47. dragonslaya84

    dragonslaya84

    Joined:
    Aug 10, 2014
    Posts:
    4
    Well when i do the NetworkManager.Instance.StartHost it automically does the hosting and client connection. And the client variable is not null but when i try to do startallClient and then use the same variable .client its null. So i assum that when you start hosting the client variable gets set internally, but when i try to do the actualy startclientall method it does not set the client variable.

    So when i create a match i do this to start hosting right away.
    Code (csharp):
    1.  
    2.                     // Lobby has been successfully created and we will want to store the lobby id
    3.                     // for this match in-case we wanna do things later with it.
    4.                     SteamworksManager.Instance.CurrentLobbyId = (CSteamID) callback.m_ulSteamIDLobby;
    5.  
    6.                     // Let's set lobby data to store lobby name.
    7.                     SteamHelpers.SetLobbyName(_matchname.text);
    8.  
    9.                     // Reset server in case of left behind info.
    10.                     NetworkServer.Reset();
    11.  
    12.                     // Start unet network manager now.
    13.                     UNetNetworkManager.Instance.StartHost();
    14.  
    15.                     UNetNetworkManager.Instance.client.Send(OmnMsgType.SelectedMap,
    16.                         new IntegerMessage(_mapSelectionCombobox.ListView.SelectedIndex));
    17.  
    18.                     // Clear input field.
    19.                     _matchname.text = "";
    20.  
    21.                     // Enable room match and disable lobby lists panels.
    22.                     _matchPanel.SetActive(true);
    23.                     _lobbiesPanel.SetActive(false);
    24.  
    25.  
    26.  
    When on the client side i try to join the match i created like this.

    Code (csharp):
    1.  
    2.  
    3.  
    4.                     // Joined or created lobby successfully. Will want to store the lobby id
    5.                     // for this match in-case we wanna do things later with it.
    6.                     SteamworksManager.Instance.CurrentLobbyId = (CSteamID) callback.m_ulSteamIDLobby;
    7.  
    8.                     if (UNetNetworkManager.Instance.client == null)
    9.                         // Let's connect unet to hoster before building lobby list.
    10.                         UNetNetworkManager.Instance.StartClientAll(SteamHelpers.GetHosterPublicIp(),
    11.                             SteamHelpers.GetHosterInternalIp(), SteamHelpers.GetGuidId(),
    12.                             (NetworkID) SteamHelpers.GetMatchId());
    13.  
    14.  
    So the UNetNetworkManager.Instance.client after that code fires off is always null and i cant do

    Code (csharp):
    1.  
    2.             // Set our ready status to false, character selected to -1 and our steam id.
    3.              UNetNetworkManager.Instance.client.Send(UnityEngine.Networking.MsgType.LobbyReadyToBegin,
    4.                 new PlayerReadyMessage {IsReady = false, CharacterIndex = -1, PlayerId = SteamUser.GetSteamID()});
    5.  
    6.  
    on the client
     
  48. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    Are you waiting for the client to actually connect? It will be null until OnClientConnect() has been called. Also it looks like you're calling StartHost() when you should be calling StartHostAll().
     
  49. dragonslaya84

    dragonslaya84

    Joined:
    Aug 10, 2014
    Posts:
    4
    Thank you i didnt know i needed to use starthostall. That fixed maybe the one issue nad you are correct the OnClientConnect isnt firing off before my code fires off.
     
  50. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    909
    is support android ?