Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

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

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

  1. VitorCarvalhoGameDev

    VitorCarvalhoGameDev

    Joined:
    Aug 13, 2015
    Posts:
    2
    Hello thegreatzebadiah,

    Your product seems really good, but before i buy it id like to ask if is the host migration is really working and there is any example on how to implement it?

    Cumps
     
  2. Jawsarn

    Jawsarn

    Joined:
    Jan 12, 2017
    Posts:
    218
    Hi, so I just bought the asset and well, it didn't start off good :(
    I modified the example scene a bit to join with "StartClientAll(IP, internal_IP, port, natHelper.guid);" when pressing join. I enabled the unity multiplayer service, and enabled all the connection options on the Example Network Manager.

    From the server I get the info of IP and port from the variables: "hostExternalIP, hostInternalIP, networkPort". And manually typed it in on the client in "StartClientAll".

    From the testing from the available computers we had, same network connections worked both ways (both trying to be host). Different networks worked in one instance one way, and the other times not.

    A snippet of warning messages I get:

    NATHelper: NAT Device not found
    NATHelper: Punchthrough attempt timed out
    Punchthrough failed

    Shouldn't the relays make things work when the Punchthrough fail? Or is there some additional code I need to put in the example network manager to get all the things to work? Could it have something to do with requiring IPv6 instead? (I'm a bit at the loss here)

    Thanks for any hints or advice :)
    //Christian

    (SOLVED)
     
    Last edited: Aug 25, 2017
  3. Jawsarn

    Jawsarn

    Joined:
    Jan 12, 2017
    Posts:
    218
    Further testing with two scenes, one using the old lobby manager, and one with the NAT lobby manager; shows that both work when hosting and joining with Unity Matchmaking. However, NAT-punch has yet to succeed once, as it fallbacks on relay here. Does StartClientAll with IP not fallback on relay? The documentation said it should.

    // Christian
     
  4. VitorCarvalhoGameDev

    VitorCarvalhoGameDev

    Joined:
    Aug 13, 2015
    Posts:
    2
    Hello, sometimes when i disconnect a player from a current match and try to host another there is this error:
     

    Attached Files:

  5. Jawsarn

    Jawsarn

    Joined:
    Jan 12, 2017
    Posts:
    218
    Well, I feel a bit stupid here. Obviously the answer was the simplest. The GUID can't be fetched from natHelper.guid on the client, but needs to be sent over from the host. Still not connected yet however with punch through, getting some timeout disconnects now, but I'll see if I'll manage those myself. I still feel it was werid that the UNET relays didn't kick in when the punch through failed?
     
  6. Jawsarn

    Jawsarn

    Joined:
    Jan 12, 2017
    Posts:
    218
    Still a bit at a loss, we get disconnection timeouts at around 15~ seconds after "OnHolePunchedClient" is called with success as true.

    http://imgur.com/a/auM4u
     
  7. mightybob

    mightybob

    Joined:
    Mar 23, 2014
    Posts:
    75
    Hey. Just wanted to let you know, the facilitator on grabblegames.com used for testing is down again. I will definitely be switching to my own servers when I get closer to release, but for now I'm using your test/development servers. I'm aware of some free virtual server options but I've already gone thru quite a few free trials. Thanks for reading.
     
  8. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    @mightybob Thanks for letting me know, it's back up now.

    @VitorCarvalhoGameDev Host migration is working last I checked at least. There is an example included with the plugin that should get you started.

    To everyone else: I was out of town for a couple of days but I'm looking into all of your issues now. Thanks for your patience.
     
    mightybob likes this.
  9. Jawsarn

    Jawsarn

    Joined:
    Jan 12, 2017
    Posts:
    218
    I think amazon free tier (I just put my up on it) should be free for the amount of computation required (https://aws.amazon.com/free/). Took me about 1,5h (for one noobish at SSH and ftp) to get it up. :)

    (EDIT)
    Would probobly take me 20 mins if I just followed the guides for putty and FileZilla directly x)
     
    Last edited: Aug 28, 2017
  10. WaaghMan

    WaaghMan

    Joined:
    Jan 27, 2014
    Posts:
    241
    Hi, we're thinking of adding a dedicated server mode to our game, and I think that the plugin doesn't really support that (Unless I'm wrong, we would need a StartServerAll method instead of StartHostAll ). It may be a bit too much to ask, but any chance you might look into adding support for it?
     
  11. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    @WaaghMan Hmmmm, it's not something I ever really considered since normally if you're going with dedicated servers you're not going to run into NAT issues, since you have complete control over the hosts...but I'm guessing you're talking about users hosting their own dedicated servers? in which case I can see how nat traversal would be helpful..

    I'll take it in to consideration. Hopefully it's a fairly straight forward fix. No promises though, if it looks like a huge change it may not happen for a while.
     
  12. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    @bonkabonkstudios

    Rejoining seems to be working for me on the Example scene. Are you maybe overriding OnClientSceneChanged() and not calling the base method?
     
  13. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    @jawswch I think I'll need to see some of your code to really help you debug. It sounds like you are making some progress though. It looks like you've already figured out that the guid has to be passed from the host to the clients somehow. Maybe another part that you are missing is that the match ID also has to be passed from from the host to the clients in order for the relays to work. Even when not using matchmaking the host still creates a match since that's just how the relays work. The clients need the id of that match so they can join if other connection methods fail.

    I'm not sure about the disconnect issue you are experiencing. It could be anything really. If you can email me a small project that I can use to replicate the issue it would definitely help.

    Cheers
     
  14. Jawsarn

    Jawsarn

    Joined:
    Jan 12, 2017
    Posts:
    218
    Thanks for the reply! I almost figured as much with the matchID. Still haven't figure out the disconnecting issues, I sent a link to the code to the support mail at https://www.assetstore.unity3d.com/en/#!/content/58948 .

    It could be that the nat punch just simply is failing? But it is werid that it would return true for the success of "OnHolePunchedClient". I'd guess it would return false if NAT punch failed?

    Many thanks for taking your time!
     
  15. kjuanlu

    kjuanlu

    Joined:
    Dec 4, 2011
    Posts:
    100
    @thegreatzebadiah Hello! Nice work with the plugin.

    I'm testing your solution in our project and it works after changing some lines of code. But when I try to connect two computers in the same LAN, it connects by relay server, is it normal?

    Regards
     
  16. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    @kjuanlu That doesn't really sound normal. Maybe the internal or external IP isn't being properly passed from host to client for some reason. Generally when connecting via LAN it will use the internal IP so there shouldn't really be any issues with NAT and it should be able to connect directly.

    It may also be an issue with windows or a firewall blocking the connection, probably on the host.
     
    Last edited: Aug 29, 2017
  17. Jawsarn

    Jawsarn

    Joined:
    Jan 12, 2017
    Posts:
    218
    @thegreatzebadiah Poke me if you can't recreate the problem and need to a bad end to connect to : )
     
  18. kjuanlu

    kjuanlu

    Joined:
    Dec 4, 2011
    Posts:
    100
    Thank you, it was the firewall. If you make a build, windows ask you to add a firewall exception, but while running on editor the firewall blocks the connection.

    And for next users, I needed to change the
    Code (csharp):
    1. NetworkClient.allClients[0].SendByChannel...
    to
    Code (csharp):
    1.  
    2. foreach (var conn in NetworkClient.allClients)
    3. if (conn.isConnected) conn.SendByChanne.....;
    Regards
     
  19. golergka

    golergka

    Joined:
    Mar 15, 2012
    Posts:
    30
    Is your plugin using MsgType of 32763?

    I'm trying to diagnose network issues in my project, and I'm using NetworkClient.GetConnectionStats() method. In there, I see known built-in messages as well as my own custom ones. But I also see a mysterious 32763 message.

    May be it's a special message used in this plugin?
     
    Last edited: Sep 1, 2017
  20. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    @golergka Yep. There are actually three MsgTypes used by the plugin:

    Code (CSharp):
    1.  
    2.     public class MsgType : UnityEngine.Networking.MsgType
    3.     {
    4.         public static short ReplaceConnection = short.MaxValue - 5;
    5.         public static short SetConnectionInfo = short.MaxValue - 4;
    6.         public static short ExtraPeerInfo = short.MaxValue - 3;
    7.     }
    I really wasn't sure what the best approach was for this so I just picked some IDs way at the end. I'm open to other suggestions.
     
  21. kew2001

    kew2001

    Joined:
    Dec 29, 2015
    Posts:
    10
    Hi,

    I can't get this to work when using the ExampleNATHelperOnly example when initiating the connection workflow from OSX to Windows.

    The issue is that OSX is asked to listen on port 0/

    I start the example in Unity 2017.1.1 Running on Windows and OSX. I am running my own instance of the "Facilitator"

    1) On OSX: Click "Listen for Punchthrough"
    2) On Windows: Enter the Host GUID from OSX into "Host GUID" field in Windows and click "Punchthrough"
    3) On OSX I am told "Start a server listening on this port: 0 for client 576460764839005709"

    if I reverse this and initiate listen for Punchthrough on Windows, everything works fine.

    Here is a log...

    NATHelper: Searching for nat devices
    NATHelper: NAT Device not found
    0 libsystem_c.dylib 0x00000000c05cc1fb thread_stack_pcs + 11
    1 Unity 0x000000000241bab2 backtrace + 18
    2 Unity 0x000000000120e0e8 _Z13GetStacktracei + 104
    3 Unity 0x000000000157a6a5 _Z17DebugStringToFileRK21DebugStringToFileData + 421
    4 Unity 0x00000000015784cd _Z17DebugStringToFilePKciS0_i15LogMessageFlagsiiPFvRK11CppLogEntryE + 93
    5 Unity 0x0000000001ebdfe9 _Z35DebugLogHandler_CUSTOM_Internal_Log7LogTypeP10MonoStringP10MonoObject + 505
    6 [Mono JITed code] (wrapper managed-to-native) UnityEngine.DebugLogHandler:Internal_Log (UnityEngine.LogType,string,UnityEngine.Object) + 0xa5 (0x11fd059b0 0x11fd05a84) [0x136bb3000 - Unity Child Domain]
    7 [Mono JITed code] UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[]) + 0xc0 (0x11fd058b0 0x11fd05994) [0x136bb3000 - Unity Child Domain]
    8 [Mono JITed code] UnityEngine.Logger:Log (UnityEngine.LogType,object) + 0x195 (0x11fd05010 0x11fd051c9) [0x136bb3000 - Unity Child Domain]
    9 [Mono JITed code] UnityEngine.Debug:LogWarning (object) + 0x92 (0x11fe38b00 0x11fe38bb6) [0x136bb3000 - Unity Child Domain]
    10 [Mono JITed code] NATTraversal.NATHelper:Update () + 0x2a1 (0x11fe381f0 0x11fe3864d) [0x136bb3000 - Unity Child Domain]
    11 [Mono JITed code] (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr) + 0xfa (0x119d7b220 0x119d7b44d) [0x136bb3000 - Unity Child Domain]
    12 libmono.0.dylib 0x000000003643ac66 mono_get_runtime_build_info + 3654
    13 libmono.0.dylib 0x0000000036565dba mono_runtime_invoke + 117
    14 Unity 0x00000000019c774d _ZN19ScriptingInvocation6InvokeEP21ScriptingExceptionPtrb + 125
    15 Unity 0x000000000168e0d6 _ZN13MonoBehaviour21CallMethodIfAvailableEi + 470
    16 Unity 0x00000000012cef0b _ZN20BaseBehaviourManager12CommonUpdateI16BehaviourManagerEEvv + 507
    17 Unity 0x00000000012ceccf _ZN16BehaviourManager6UpdateEv + 47
    18 Unity 0x00000000015cc848 _ZZ23InitPlayerLoopCallbacksvEN41UpdateScriptRunBehaviourUpdateRegistrator7ForwardEv + 40
    19 Unity 0x00000000015ccf63 _Z10PlayerLoopv + 931
    20 Unity 0x000000000036a500 _ZN11Application11UpdateSceneEb + 576
    21 Unity 0x000000000036ac4a _ZN11Application13EnterPlayModeEb + 682
    22 Unity 0x000000000036659b _ZN11Application12SetIsPlayingEb + 171
    23 Unity 0x0000000000365d8c _ZN11Application9TickTimerEv + 4268
    24 Foundation 0x00000000ac8a2e0f __NSFireTimer + 83
    25 CoreFoundation 0x00000000aae18c54 CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION + 20
    26 CoreFoundation 0x00000000aae188df __CFRunLoopDoTimer + 1071
    27 CoreFoundation 0x00000000aae1843a __CFRunLoopDoTimers + 298
    28 CoreFoundation 0x00000000aae0fb81 __CFRunLoopRun + 2065
    29 CoreFoundation 0x00000000aae0f114 CFRunLoopRunSpecific + 420
    30 HIToolbox 0x00000000aa36febc RunCurrentEventLoopInMode + 240
    31 HIToolbox 0x00000000aa36fcf1 ReceiveNextEventCommon + 432
    32 HIToolbox 0x00000000aa36fb26 _BlockUntilNextEventMatchingListInModeWithFilter + 71
    33 AppKit 0x00000000a8908a54 _DPSNextEvent + 1120
    34 AppKit 0x00000000a90847ee -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 2796
    35 AppKit 0x00000000a88fd3db -[NSApplication run] + 926
    36 AppKit 0x00000000a88c7e0e NSApplicationMain + 1237
    37 Unity 0x0000000002201755 _Z10EditorMainiPPKc + 853
    38 Unity 0x0000000002201bc9 main + 9
    39 libdyld.dylib 0x00000000c058f235 start + 1

    NATHelper: NAT device found
    NATHelper: Received RakNet message: XX.XXX.XX.XXX|51341: ID_CONNECTION_REQUEST_ACCEPTED
    NATHelper: Connected to Facilitator: 1505024525501080
    Listening for punchthrough
    NATHelper: Listening for punchthrough
    NATHelper: Received RakNet message: 192.168.0.33|58028: ID_NAT_PUNCHTHROUGH_SUCCEEDED
    NATHelper: Received punch-through: 192.168.0.33|58028
    NATHelper: Received RakNet message: 192.168.0.33|58028: ID_NEW_INCOMING_CONNECTION
    NATHelper: Received incoming RakNet connection.
    NATHelper: Received RakNet message: 192.168.0.33|58028: ID_DISCONNECTION_NOTIFICATION
    NATHelper: Received RakNet message: XX.XXX.XX.XXX|51341: ID_DISCONNECTION_NOTIFICATION
    NATHelper: Hole is punched on port: 0
    Start a server listening on this port: 0 for client 576460764839005709
    NATHelper: Received RakNet message: XX.XXX.XX.XXX|51341: ID_CONNECTION_REQUEST_ACCEPTED
    NATHelper: Connected to Facilitator: 1505024525501080
    NATHelper: Listening for punchthrough
     
    Last edited: Sep 12, 2017
  22. Scornz

    Scornz

    Joined:
    Jun 15, 2014
    Posts:
    27
    Whenever I try to use StartClientAll, I get an error of "Number of connections should be > 0"... this only happens with StartClientAll not Unity's default JoinMatch. Any advice?
     
  23. Kalle801

    Kalle801

    Joined:
    Mar 3, 2013
    Posts:
    80
    do i understand it right: Can i create a complete p2p Multiplayer without the need of Unet and CCU limit?
     
  24. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    @kew2001 I'm looking into it, but I have a feeling it more to do with your router / network than it being osx (though I could easily be wrong). Are both computers you're testing with behind the same router or separate routers? Are you in a school or office environment that may have strange non-standard router settings? Is either computer using wifi?

    @ScornzGames That's pretty odd. I would test in the Example scene and see if it works there. If so try and figure out what you're doing differently from the ExampleNetworkManager. You're probably overriding a method without calling the parent method.

    @Kalle801 That is correct with one condition: without the relays there is no way to guarantee that a connection can always be made. Punchthrough / port forwarding is very effective but it's not 100% and some players simply will not be able to connect to each other. To be specific punch through will fail in cases where both the host and the client are behind routers with symmetric NAT, which from our research / tests comes out to somewhere between 5 and 15% of connections. At that point your only options are to ask your users to manually change their routers settings, or accept that some connections are just going to fail. Both options suck which is why I usually recommend sticking with the relays if possible. Yeah it's lame that they cost money, but with the plugin you'll only be using them for about 5-15% of connections. I'd say it's worth the cost to guarantee that your players can connect.
     
  25. kew2001

    kew2001

    Joined:
    Dec 29, 2015
    Posts:
    10
    Thanks. I'm at a home environment. Both computers are on the same network behind the same router. OSX behaves this way if it is on Wifi or physically connected.

    Works when I use two Windows 10 machines.
     
  26. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    @kew2001 I've got the mac issue fixed. It will be in the next update, which I should have submitted tonight or tomorrow.
     
  27. dylan92

    dylan92

    Joined:
    Jul 10, 2012
    Posts:
    32
    @thegreatzebadiah I'm running into an issue with NAT Traversal and Unity's matchmaking service. After I host a match (via StartHostAll) I can see my match listed in the results from the matchmaker and I can see that my CCU in the multiplayer service has gone up. After about 15 seconds other clients can no longer see that match in the list of matches from the matchmaker and I see that my CCU has gone back down to 0. Have you seen anything like this before? I'm not seeing any logs or anything that would indicate why my match is getting removed from the matchmaking service. I'm running Unity 2017.1.1 and the latest version of NAT Traversal.
     

    Attached Files:

  28. Eideren

    Eideren

    Joined:
    Aug 20, 2013
    Posts:
    308
    Hey, your System.Threading.dll is still creating conflicts with the .NET 4.6 runtime, it's been more than four months now, is there any ETA on that ?
     
  29. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    @Eideren Thank you for bringing this back up. I wish you had reminded me sooner. I jumped on it as soon as I saw your message and I think I just got it all working.

    I'll get it submitted tonight or tomorrow but if you want to get it immediately shoot me an email to the support email.

    There will be some steps to get it working that you'll have to do manually since unity doesn't give me any way to specify which dll to use for each version of .NET. I'll make sure to write it up in the readme but you'll need to check / uncheck some checkboxes in the dll import settings to switch from the .NET 3.5 versions of the dll's to the .NET 4.6 versions.
     
  30. Eideren

    Eideren

    Joined:
    Aug 20, 2013
    Posts:
    308
    That's fantastic, thanks a bunch !
     
  31. My64K

    My64K

    Joined:
    Jun 11, 2015
    Posts:
    10
    Tested - yes it now works under OSX! Thankyou!
     
    thegreatzebadiah likes this.
  32. alan-lawrance

    alan-lawrance

    Joined:
    Feb 1, 2013
    Posts:
    354
    The FAQ states that the built-in Unity matchmaking cannot be used, but I didn't see this called out in the docs (and some forum posts suggest you can use Unity matchmaking).

    It's probably better to use Steam lobbies, but I want to understand what is possible and what the pros/cons are for using Unity matchmaking vs Steam.
     
  33. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    @alan-lawrance Unity matchmaking works fine, the only part that doesn't working is migrating relay connections because it's just not supported by Unity.
     
  34. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    Kind of sounds like you're getting disconnected from the relay for using too much bandwidth.
     
  35. alan-lawrance

    alan-lawrance

    Joined:
    Feb 1, 2013
    Posts:
    354
    OK, that sounds like anyone connected through Unity matchmaking would be stuck using relay servers. Since we want to minimize the use of relay servers, it would make sense to avoid Unity matchmaking. Is that accurate?

    Also -- how does Unity get away with forcing everything through relay servers at $0.49/GB when most of the time it's not necessary. Surely they are dragging their feet on this.
     
    Last edited: Sep 25, 2017
  36. BmDeveloperz

    BmDeveloperz

    Joined:
    Jul 1, 2013
    Posts:
    62
    @thegreatzebadiah i think there is a problem with creating a match with a defined name. My current project cannot list the matches with the names i'm looking for. To be sure, i downloaded the latest example scene and tested, not working on example scene either.

    I created a string variable and replaced with "Hello World".

    StartHostAll(MatchName, customConfig ? (uint)(maxConnections + 1) : matchSize);

    for joing also i changed the string.

    matchMaker.ListMatches(0, 10, MatchName, true, 0, 0, OnMatchList);

    When i try to join with an empty string its working fine. But when i try to type the same name as the server has, i got a debug log says;

    Match list is empty
    UnityEngine.Debug:Log(Object)
    ExampleNetworkManager:OnMatchList(Boolean, String, List`1) (at Assets/NAT Traversal Example/ExampleNetworkManager.cs:38)
    UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

    Also when i get the match info by using "match.name", i get this result while my server name is "12345";

    default|192.168.1.129|178.251.43.170|fe80::e577:fb58:b055:f178||7777|1004303844409422865

    I hope this is a bug because i'm creating matches using SteamID and using it to join our friends games which is not working anymore. If its not, i would be grateful if anyone can tell me how to pass this info through match infos.

    Thanks.
     
    Last edited: Sep 26, 2017
  37. BmDeveloperz

    BmDeveloperz

    Joined:
    Jul 1, 2013
    Posts:
    62
    Also i tried to use getMatchNameFromConnectionInfo() but still i'm getting the same result. Maybe i'm missing something or doing something wrong. Does anyone got the same issue ?
     
  38. BmDeveloperz

    BmDeveloperz

    Joined:
    Jul 1, 2013
    Posts:
    62
    @thegreatzebadiah the server name registration is not working somehow. It's set to "default" all the time. So that's why i can't get my server list. If it's plugin related bug, i would be grateful if i could get a quick fix.

    Thanks.
     
  39. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    @Olcay. Yep, definitely a bug. I know that was working recently so I'm not sure how I messed that up but it will be fixed in the next release. If you want the update immediately you can email me at the support email and let me know what version of unity you're using.
     
    Last edited: Sep 28, 2017
    BmDeveloperz likes this.
  40. Spacewalker

    Spacewalker

    Joined:
    Nov 28, 2016
    Posts:
    12
    Hello, I would like to know NAT Traversal will work on mobile devices if they only connect (without the ability to create a server) to the server (or dedicated server) on the computer?
     
  41. Sorobaid

    Sorobaid

    Joined:
    Aug 31, 2012
    Posts:
    13
    Hi, Can I get some help for connecting without using Unity matchmaking (untick unity matchmaking):
    1. Do I need to tick the connect to relay server? This is related to next question
    2. To join a match, what is the most necessary parameters needed for StartClientAll? I have been trying to connect to a host server in same LAN on Windows but it always fail. Right now I am sending everything from guid, external ip, internal ip, external ip v6, internal ip v6, but not the match network id since I cannot find out how to create a new unity network id
    3. I always get this warning when running in unity editor to join a match NATHelper: Something went wrong mapping port 64178->64178 (Udp) & also the Tcp one. Is it normal?
    Sorry if this is repeated question.
     
  42. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    Unfortunately the plugin is not compatible with mobile devices. There have been attempts to get it working in the past but I'm not sure if anyone ever succeeded. If you search this forum post you can probably find some more info, but the short version is that it's not going to work out of the box.

    Also, even if it was compatible with mobile devices, it would only really be effective for wifi connections. Punchthrough doesn't really work on mobile networks.
     
  43. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    @Sorobaid
    1. It's up to you, but without the relays you are not guaranteed to be able to connect. There are cases where port forwarding and punchthrough just aren't possible, so if you want connections to work in these cases you'll need the relays.
    2. It sounds like you're passing all the right things in. If you are using the relays though you should also pass in the match network id. Even when you're not using unity matchmaking a match is still created because that's how clients join via relay. If you're not using relays then you won't have a match network id to pass in since no match is created.
    3. It looks like your router either does not support port forwarding or has port forwarding disabled.

    From what you've described I'd say either your router / network configuration is restrictive / non-standard, or you've got a windows firewall blocking either the editor or build, or you've just done something wrong in your code. There are cases where punchthrough isn't possible, but since you're connecting two computers on the same LAN I don't think that's the issue here.

    Check the firewall settings on both computers and if nothing is blocked and you still can't connect then hit me up at the support email and send me some code or a project that I can use to replicate the issue.
     
  44. JBrito

    JBrito

    Joined:
    May 29, 2015
    Posts:
    2
    Support Mobile?? Thanks o/
     
  45. Sorobaid

    Sorobaid

    Joined:
    Aug 31, 2012
    Posts:
    13
    @thegreatzebadiah thanks, looks like it is indeed from the router. Now it can connect.
    1. Do you happen to know any other relay server that can exchange unity one, if possible the one that I can install in dedicated server? Is the steamwork one of them?
    2. Yeah, I test this by manually inputting everything. So just like my question before, I simply cannot find the method to change from number to unity network id.
    Anyway thanks man for the good work for the plugin
     
  46. NFMynster

    NFMynster

    Joined:
    Jul 1, 2013
    Posts:
    66
    Have you thought of supporting either your own or some other master server (Master server framework) into this, making the asset able to list servers and connect to them, making it completely independent from Unity's paywall? I think it certainly would bring a lot of attention, I would buy it straight away.
     
  47. kew2001

    kew2001

    Joined:
    Dec 29, 2015
    Posts:
    10
    Hi,

    I've integrated your plugin into my game and I'm getting mixed results. When testing from home with both machines behind the same NAT, I get varying success rates with a connection. I can connect between machines *eventually* but it takes a lot of retries. On average if I retry 4 times I can get a connection eventually, always.

    As I get the punchthrough events on client/host I....
    • On the client I create a UDP listening socket on the specified port.
    • On the host I open a UDP client socket to the specified address/port and I send a UDP "PING" packet to the client.

    I do a PING/PONG/PANG back and forth to make sure I have full two way communication, at which point I deem the connection to be open on both sides.

    The issue is getting that first PING between host and client. It will more often than not fail. Then after three PINGs with a one second period I give up and instruct the client via my own websocket server relay to retry standing up the connection from scratch.

    Like I said - on average it takes 4 of these cycles to stumble onto a connection.

    I'm wondering what I am doing wrong? Is this normal?

    Should I create a whole new NATHelper object each time I make a connection or can I recycle it as I am now? In testing I have noticed that cold restarting the game compared to exiting the network lobby makes no real difference to reliability.

    Before each attempt I recycle the NATHelper object by calling Init()

    Code (CSharp):
    1.  
    2.         /// <summary>
    3.         /// Intialise the NAT Helper before each connection is attempted.
    4.         /// </summary>
    5.         public static void Init()
    6.         {
    7.             // We need a working NAT helper.
    8.             if (natHelper == null)
    9.             {
    10.                 natHelper = GameObject.Find("NATHelper").GetComponent<NATHelper>();
    11.                 natHelper.findNatDevice();
    12.                 natHelper.StartCoroutine(natHelper.connectToNATFacilitator());
    13.                 NetworkTransport.Init();
    14.             }
    15.             else
    16.             {
    17.                 // Reset the state to recycle it.
    18.                 Reset();
    19.             }
    20.         }
    21.  
    22.         /// <summary>
    23.         /// Reset the NAThelper.
    24.         /// </summary>
    25.         static void Reset()
    26.         {
    27.             Rivalry.Debug.LogFormat("NAT helper reset.");
    28.  
    29.             if (natHelper.isListeningForPunchthrough)
    30.             {
    31.                 natHelper.StopListeningForPunchthrough();
    32.             }
    33.  
    34.             if (natHelper.isForwardingPort)
    35.             {
    36.                 natHelper.stopPortForwarding();
    37.             }
    38.  
    39.             if (natHelper.isPunchingThrough)
    40.             {
    41.                 natHelper.StopPunchingThrough();
    42.             }
    43.         }
    I'm running a Facilitator on my own server. Is there a more reliable way to run it? I remember reading something about running two of them at once was more reliable?

    When I test in an environment when punchthrough is going to fail (multi NAT) I get this message in the logs - but I don't get a callback or anything that I could use to trigger a retry or give up. Is there any way I can get access to this failed state in the code?

    Code (CSharp):
    1. NATHelper: Unexpected raknet message received: ID_NAT_PUNCHTHROUGH_FAILED
    2.  
    I have also noticed that I get this "error" when I make I attempt to make a connection. I don't think it is a real error, are you just logging this as an error?

    nat listen port: 62370
    0x000000014098D85B (Unity) StackWalker::GetCurrentCallstack
    0x0000000140990E0F (Unity) StackWalker::ShowCallstack
    0x0000000140D36CE0 (Unity) GetStacktrace
    0x000000014107C036 (Unity) DebugStringToFile
    0x000000014107C80C (Unity) DebugStringToFile
    0x000000014186C412 (Unity) DebugLogHandler_CUSTOM_Internal_Log
    0x000000000C0FABBB (Mono JIT Code) (wrapper managed-to-native) UnityEngine.DebugLogHandler:Internal_Log (UnityEngine.LogType,string,UnityEngine.Object)
    0x000000000C0FAAA4 (Mono JIT Code) [DebugLogHandler.cs:9] UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[])
    0x0000000034CF1585 (Mono JIT Code) [Logger.cs:47] UnityEngine.Logger:Log (UnityEngine.LogType,object)
    0x0000000034DF79B3 (Mono JIT Code) [DebugBindings.gen.cs:124] UnityEngine.Debug:LogError (object)
    0x0000000034DF6CDC (Mono JIT Code) NATTraversal.NATHelper:listenForPunchthrough (RakNet.Packet)
    0x000000000C0FDCEF (Mono JIT Code) NATTraversal.NATHelper/<messageLoop>d__65:MoveNext ()
    0x000000000C0FC241 (Mono JIT Code) [Coroutines.cs:17] UnityEngine.SetupCoroutine:InvokeMoveNext (System.Collections.IEnumerator,intptr)
    0x000000000C0FC58B (Mono JIT Code) (wrapper runtime-invoke) <Module>:runtime_invoke_void_object_intptr (object,intptr,intptr,intptr)
    0x00007FFCCF8E5EDF (mono) [mini.c:4937] mono_jit_runtime_invoke
    0x00007FFCCF838731 (mono) [object.c:2623] mono_runtime_invoke
    0x000000014140BF25 (Unity) scripting_method_invoke
    0x0000000141403FE1 (Unity) ScriptingInvocation::Invoke
    0x000000014115AC0C (Unity) Coroutine::InvokeMoveNext
    0x000000014116BE9C (Unity) Coroutine::Run
    0x0000000140DD649A (Unity) DelayedCallManager::Update
    0x00000001410B754C (Unity) `InitPlayerLoopCallbacks'::`39'::UpdateScriptRunDelayedDynamicFrameRateRegistrator::Forward
    0x00000001410B5391 (Unity) PlayerLoop
    0x00000001401091FE (Unity) Application::UpdateScene
    0x000000014010D54F (Unity) Application::UpdateSceneIfNeeded
    0x00000001401318BF (Unity) Application::TickTimer
    0x0000000141A8A84D (Unity) MainMessageLoop
    0x0000000141A8C15E (Unity) WinMain
    0x0000000141CEF53C (Unity) __tmainCRTStartup
    0x00007FFD20CD2774 (KERNEL32) BaseThreadInitThunk
    0x00007FFD22F60D51 (ntdll) RtlUserThreadStart
     
    Last edited: Oct 9, 2017
  48. My64K

    My64K

    Joined:
    Jun 11, 2015
    Posts:
    10
    Everything is good!

    1) Looks like I don;t have the P2P reliability issue when connecting from different networks - just my own.
    2) Although I don't get access to the failure notification on the client side - I do on the host side - so I can initiate a retry or give up by signalling my own relay connection.
     
  49. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    Sorry, there is no mobile support and none is planned.
     
  50. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    No, no, and no. Sorry but I think until unity releases the source code for their relays or a standalone version for us to host ourselves you're probably going to be stuck using theirs.

    Steam actually does have their own relays but to use them you have to use Steam's networking which last I checked you can not (easily) use with unet, you'd have to use the steamworks API for all your networking or figure out how to use steam's networking via unet somehow.
     
    CloudyVR likes this.