Search Unity

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

Unity iOS and IPv6 support

Discussion in 'iOS and tvOS' started by Mantas-Puida, May 17, 2016.

  1. Mantas-Puida

    Mantas-Puida

    Unity Technologies

    Joined:
    Nov 13, 2008
    Posts:
    1,807
    Apple recently announced that beginning June 1, 2016, “all apps submitted to the App Store must support IPv6-only networking.” Since many of our users publish Unity games to the App Store, we wanted to take a moment to discuss Unity’s support for IPv6-only networks. Note that this requirement applies to both new app submissions and updates to existing apps.

    What is IPv6?

    From the Wikipedia article: “Internet Protocol version 6 (IPv6) is the most recent version of the Internet Protocol (IP), the communications protocol that provides an identification and location system for computers on networks and routes traffic across the Internet.” Devices can operate on an IPv4-only network (the previous standard), and IPv6-only network, or a network with both protocols in use. Apple’s new requirement means that apps must be able to operate in an IPv6-only network.

    It is important to understand that IPv4 and IPv6 networks do not interoperate, although it is possible to pass traffic from one type of network over the other with tunnelling.

    Does Unity support IPv6?

    Yes! WWW and UnityWebRequest are IPv6 compatible on iOS out of the box because they are based on high level Apple networking APIs. And over the past few months we have been working to bring support for IPv6-only networks to Unity’s .NET/IL2CPP libraries. Our last known IPv6 bugs related to .NET/IL2CPP were corrected in the 5.3.4p4 patch release. There is one fix pending for UNET which is going to be shipped in coming weeks. Thanks to help from great members of our community (like Exit Games) we have been able root out a number of bugs in the Unity Engine code and provide support for IPv6-only networks on the following platforms:

    • Editor: All platforms
    • Standalone player: All platforms
    • iOS
    • Android
    We’ll continue to add support for IPv6-only networks on other platforms in the future.

    What about older versions of Unity?

    If you are using only WWW or UnityWebRequest APIs to access network resources you should be fine, though please test your games carefully.

    We are also planning to backport our .NET/IL2CPP fixes to selected older lines of Unity and release them as 4.7.2, 5.1.5 and 5.2.5 updates.

    What should you do?

    First, test your game in IPv6-only setup to assess if all the game features work as intended. This guide from Apple goes through the setup of an IPv6-only testing network using a Mac with OS X 10.11 or later. This is the same testing that App Store reviewers will use, so it is a good place to start with IPv6 testing. Since IPv4 and IPv6 networks cannot interoperate, you must test on an IPv6-only network to ensure everything is working well. If your device has both IPv6 and IPv4 addresses, then socket operations could succeed using IPv4.

    Second, audit your code for a few indicators of possible problems:

    • Look for the use of IPv4 addresses (e.g. 127.0.0.1, 8.8.4.4). Any use of such hardcoded addresses should be removed. Prefer host names, which can be used to look up the proper IPv4 or IPv6 address of a given device for the proper type of network.
    • Look for the use of the IPAddress.AddressFamily property. If the code branches based on the value of the property, is there a branch that handles IPv6 properly?
    • Look for the use of the IPAddress.Any and IPAddress.Loopback fields. These fields work with IPv4 addresses, not IPv6 addresses. Use the IPAddress.IPv6Any and IPAddress.IPv6Loopback fields as well to ensure IPv6 support.
    If you encounter troubles beyond the ones mentioned above, please make sure you are using a build with the necessary fix in it. If a fix has not yet landed in your line (4.7.x, 5.1.x, 5.2.x), wait until we have released a patch with it. Then proceed to upgrade to this version.

    Some of 3rd party native and managed networking plugins might also be not compatible with IPv6 networks, please consider reaching out plugin vendor for their compatibility status.

    Finally, let us know if you encounter bugs in Unity related to IPv6. We will work hard to correct them as soon as possible. I’ll be hanging out there to help.

    P.S. this is mirror re-post of our blog post: http://blogs.unity3d.com/2016/05/10/unity-and-ipv6-support/

    Update: 4.7.2 is live now http://unity3d.com/get-unity/download/archive
    Update #2: 5.2.5 is live too: http://unity3d.com/get-unity/download/archive (scroll down below 5.3.x updates).
    Update #3: 5.1.5 is live too: http://unity3d.com/get-unity/download/archive (scroll down below 5.2.x updates).
     
    Last edited: Jun 7, 2016
  2. mcarriere

    mcarriere

    Joined:
    Sep 14, 2012
    Posts:
    41
    We use the Ping class to test network connectivity. Documentation of this doesn't seem to indicate support for IPv6 as the method refers to the address in dot notation, nor does a quick test of swapping out IPv6 addresses for IPv4 ones.
     
  3. Mantas-Puida

    Mantas-Puida

    Unity Technologies

    Joined:
    Nov 13, 2008
    Posts:
    1,807
    Thank you for bringing this to our attention! We are having our internal discussions if this class will support that. At the moment I would recommend to use other ways to detect internet connectivity.
     
  4. mcarriere

    mcarriere

    Joined:
    Sep 14, 2012
    Posts:
    41
    How soon will you have a response on that? Ping was far more reliable in checking connectivity than WWW, as we weren't concerned with any delay in DNS resolution.
     
  5. Mantas-Puida

    Mantas-Puida

    Unity Technologies

    Joined:
    Nov 13, 2008
    Posts:
    1,807
    No ETA at the moment. We are still looking what we can do about it. If you are in hurry I would recommend falling back to WWW method.
     
  6. Mantas-Puida

    Mantas-Puida

    Unity Technologies

    Joined:
    Nov 13, 2008
    Posts:
    1,807
    Quick update on Ping class, we aiming to fix it for 5.3 and up, unfortunately it won't make to older Unity versions.
     
  7. beQr86

    beQr86

    Joined:
    Jul 2, 2015
    Posts:
    19
    Hi,

    We went through reworking all our networking interfaces (we used to use classic http requests for backend server com and socket connections for asset download) we swapped everything with UnityWebRequest, DownloadHandler and UploadHandler from UnityEngine.Experimental.Networking

    Everything works fine on Editor and android but for iOS it just ... crashes.

    We are using : Unity 5.3.5p2
    xCode 7.2
    and iPad2 with iOS 9.3.2
    Build settings :
    • IL2CPP
    • Universal Architecture (min iOS 7.1)
    • API Level .Net 2.0
    • Strip Engine code set to OFF
    • AOT-Compile options set to : mint-trampoline 512 (we were using this for mono scripting backend)
    On Xcode :
    • Bitcode is disabled
    • optimisation level set to (for release and debug) : None[-O0]
    Here is the error we get on console when the game runs :

    Unable to find method GetProgress in [UnityEngine.dll]UnityEngine.Experimental.Networking.DownloadHandler
    .
    .
    Unable to find method ReceiveContentLength in [UnityEngine.dll]UnityEngine.Experimental.Networking.DownloadHandler
    .
    .

    [project name] was compiled with optimization - stepping may behave oddly; variables may not be available.


    When we build with mono as scripting backend things work fine. But IL2CPP is mandatory for us.
    Thank you for your help.
     
  8. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    2,756
    @beQr86

    It sounds like these methods might be getting stripped from the managed code in UnityEngine.dll. Note that even with Engine Code Stripping disabled, the IL2CPP build toolchain will still attempt to strip code from managed assemblies. You can use a link.xml file to preserve everything in the UnityEngine.dll assembly though:

    <linker>
    <assembly fullname="UnityEngine" preserve="all"/>
    </linker>

    You can find more details about the link.xml file here: http://docs.unity3d.com/Manual/iphone-playerSizeOptimization.html
     
  9. beQr86

    beQr86

    Joined:
    Jul 2, 2015
    Posts:
    19
    Thank you for your answer. We will run test with this solution and let you know. We ll also give a look at the current beta version of Unity.
     
  10. beQr86

    beQr86

    Joined:
    Jul 2, 2015
    Posts:
    19
    thank you for your help, the first thing that we tested is updating Unity to the beta version 5.4.0b21 and that actually solved the problem. We are going to try the link solution because we prefer staying on a stable unity version.
    Will let you know as well
     
  11. beQr86

    beQr86

    Joined:
    Jul 2, 2015
    Posts:
    19
    Adding <assembly fullname="UnityEngine" preserve="all"/> to the link xml file did the trick ! Thank you. We are now going to try to optimize this by re-enabling the engine code stripping and being more specific in the link file with specifiying the type range we wich to exclude from the stripping process.


    EDIT :

    The final solution we applied was to keep the code stripping classic and specifically signal type that we want to save in the link.xml file. So we added this to the link file :

    <assembly fullname="UnityEngine">
    <type fullname="UnityEngine.Experimental.Networking" preserve="all"/>
    <type fullname="UnityEngine.Experimental.Networking.*" preserve="all"/>
    </assembly>

    Thanks again for the help.
     
    Last edited: Jun 9, 2016
    Nicolas1212 likes this.
  12. CoS_Ethan

    CoS_Ethan

    Joined:
    Jun 6, 2012
    Posts:
    67
    Hey there, this is Ethan from Mechanist Games. We had a serious problem when dealing with Apple's new requirement for IPV6 compatibility. Here is the situation:

    new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);

    With above line of codes, we didn't see any error generated when running with native C# project and it can be connected to the server properly, it works good with Unity 5.3.5 testing too. But when it comes to Unity 4.7.2 (what we are currently using for our projects), we keep getting popped up error "socketexception" - address that incompatible with requested protocol.

    Is there anyone who encountered the same problem? How could we resolve it without upgrading to the latest 5.3 version as it will cost too much of our time to do so, we are now having several ready-to-submit builds waiting for a solution. Thanks in advance!
     

    Attached Files:

    Last edited: Jun 12, 2016
    HansWong likes this.
  13. Mantas-Puida

    Mantas-Puida

    Unity Technologies

    Joined:
    Nov 13, 2008
    Posts:
    1,807
    Please submit a bugreport and share your case number.
    Thanks!
     
  14. CoS_Ethan

    CoS_Ethan

    Joined:
    Jun 6, 2012
    Posts:
    67
    We are in a really big hurry, what is the fastest way to make Unity aware of the bug?
     
  15. CoS_Ethan

    CoS_Ethan

    Joined:
    Jun 6, 2012
    Posts:
    67
    Where can I submit the bugreport? Haven't done this before, thanks!
     
  16. Mantas-Puida

    Mantas-Puida

    Unity Technologies

    Joined:
    Nov 13, 2008
    Posts:
    1,807
    In Unity editor Help menu, pick "Report a bug..". Once you receive confirmation message, just send me your case number.
     
  17. CoS_Ethan

    CoS_Ethan

    Joined:
    Jun 6, 2012
    Posts:
    67
    Cool, thanks, on it!
     
  18. CoS_Ethan

    CoS_Ethan

    Joined:
    Jun 6, 2012
    Posts:
    67
    There you go: Case 804914, please help push, thanks a bunch!
     
  19. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    2,756
    @CoS_Ethan

    Can you let us know the full call stack for the exception? That might help us understand the cause of the problem. Thanks!
     
  20. CoS_Ethan

    CoS_Ethan

    Joined:
    Jun 6, 2012
    Posts:
    67
    Just had them attached, please let me know if this helps.
     

    Attached Files:

    Last edited: Jun 13, 2016
  21. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    2,756
    @CoS_Ethan

    Thanks for the information. This should work with 4.7.2. I'll try it locally as well, but can you confirm that the revision hash of the Unity editor you are using is a7fe7b7f3d1f? You can check this by holding the alt key while you open the About dialog in the Unity editor. That will cause the revision hash to show up in the version information.
     
  22. CoS_Ethan

    CoS_Ethan

    Joined:
    Jun 6, 2012
    Posts:
    67
    Sure, just attached, it's indeed a7fe7b7f3d1f! Is there any other possibility that could cause such issue? We tried almost everything we could on our end, still cannot make it work.
     

    Attached Files:

  23. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    2,756
    @CoS_Ethan

    That is surprising. As I mentioned in reply the the bug report, I just tried it here with 4.7.2, and I don't see that exception. We must be doing something different, although I'm not sure what. Does this problem occur on an iOS device as well, or is it only in the editor?
     
  24. CoS_Ethan

    CoS_Ethan

    Joined:
    Jun 6, 2012
    Posts:
    67
    This error only appears with Unity editor on PC, seems like Mac and iOS have some other different error. As you don't see the exception locally, could you offer me your demo project for reference? We will compare to see if something is going wrong on our end.
     
  25. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    2,756
    @CoS_Ethan

    Actually, let me try on PC first, I used OS X for my test. However, if this doesn't happen on iOS, then it should not prevent you from shipping, I guess. What is the error you see on iOS though?
     
  26. CoS_Ethan

    CoS_Ethan

    Joined:
    Jun 6, 2012
    Posts:
    67
    We encountered two differrent errors on iOS, one is "unknown host", another is "no route to host", but the netowrk we tested before probably does not fully support ipv6, I'd prefer providing more info after a full test later. However, it would be great if we can have the demo first, it might help locate the real issue. Thanks
     
    Last edited: Jun 13, 2016
  27. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    2,756
    @CoS_Ethan

    So I can reproduce the same exception you see when I run this on the editor on PC, which is good news. Looking into the code, we explicitly decided not to back port some Windows IPv6 fixes that are in 5.3.5 to 4.7.2. So it is expected that this problem occurs in 4.7.2 in the editor. Sorry for the confusion on this point.

    However, we did back port the fixes for IPv6 necessary to make iOS work in 4.7.2, so things should be working there. Indeed, "unknown host", another is "no route to host" errors could be related to network setup, so they might be bugs. If you would like to confirm the network setup by testing in the editor, it is best to use 5.3.5, as it has all of the latest IPv6 fixes for all platforms. Once the network setup is working, then we can address any issues on iOS in 4.7.2.
     
  28. CoS_Ethan

    CoS_Ethan

    Joined:
    Jun 6, 2012
    Posts:
    67
    Hmm, ok, is it still possible for us to check the demo then? We've tested with Unity 5.3.5 already, it does work, the thing is right now we still can not upgrade to the latest version due to our own considerations. And that's why we are trying to get it resolved on 4.7.2.
     
    Last edited: Jun 14, 2016
  29. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    2,756
    @CoS_Ethan

    Sorry, I don't follow you. What is the demo you would like?
     
  30. CoS_Ethan

    CoS_Ethan

    Joined:
    Jun 6, 2012
    Posts:
    67
    Oh sure, the demo you used to test IPV6 on iOS in 4.7.2.
     
    HansWong likes this.
  31. sdfasdf3

    sdfasdf3

    Joined:
    Jun 14, 2016
    Posts:
    2
    HI,
    Does unity has any equivalent method to CAPI “getaddrinfo”?
    I tried to synthesize an IPv6 address from IPv4 address manually, by using “Dns.GetHostEntry” and “Dns.GetHostAddresses”, and none of them worked.
    We need this, because some of our submissions using fixed prefix(“64:ff9b::”) were rejected by Apple, though it works fine with our local testing pure ipv6 env.
    Any suggestion?
    Thank you!
     
  32. CoS_Ethan

    CoS_Ethan

    Joined:
    Jun 6, 2012
    Posts:
    67
    Still talking to Unity now, not sure if there is a solution yet. BTW, you come from China too? I noticed your email is 163, that's Netease.
     
  33. HansWong

    HansWong

    Joined:
    Aug 11, 2015
    Posts:
    1
    广州的
     
  34. CoS_Ethan

    CoS_Ethan

    Joined:
    Jun 6, 2012
    Posts:
    67
    Cool..yeah, we haven't found a proper solution yet either.
     
  35. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    2,756
    @CoS_Ethan

    The small project I made to test case 804914 just does this:

    Code (CSharp):
    1. void Start() {
    2.     var test  = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);
    3.     Debug.Log(test.Connected); // expect False
    4. }
    All I was trying to do was reproduce the exception during creation of an IPv6 socket. This works in the editor on OS X, but not in Windows, where I see the same exception you do. (both on 4.7.2).

    In general, we have more extensive tests for networking functionality with IPv6, but I'm not sure they are in a format where we can easily provide them without a significant amount of our other testing infrastructure.
     
  36. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    2,756
    @sdfasdf3

    There is nothing in the Unity API which is equivalent to getaddrinfo. I think that Dns.GetHostEntry is the proper method to call to get the same information. In general, this method has worked in our testing. Which version of Unity are you using, and which platforms are you testing this on?

    Also, if you have not done so yet, you may want to try creating an IPv6 address from an IPv4 address using something like this:

    Code (CSharp):
    1. var ipv4Address = "127.0.0.1";
    2. IPAddress ipv6Address = IPAddress.Parse("64:ff9b::" + ipv4Address);
    In our local testing, this works, although there may be something else in your environment causing a problem.
     
  37. CoS_Ethan

    CoS_Ethan

    Joined:
    Jun 6, 2012
    Posts:
    67
    Thanks Josh, we'll have a look shortly.
     
  38. sdfasdf3

    sdfasdf3

    Joined:
    Jun 14, 2016
    Posts:
    2
    HI, thanks for your reply.
    As I mentioned before, we have already used "64:ff9b::" prefix in our code and test ok in our local environment.
    Problem is some of our submissions passed Apple's review in some region, but others were not, and rejected by Apple. So that we turn to "getaddrinfo" equivalent since we have no idea about Apple's testing env.
    We test Dns.GetHostEntry in unity 5.3.5f1, device iOS 7.1.1, MacOS 10.11.5, xcode 7.3.1, it returns ipv6 IPAddress for names like "bing.com" but returns only ipv4 IPAddress for "192.168.0.1" like (exception is it returns both ipv4 and ipv6 address for "127.0.0.1").

    Thank you!
     
  39. bion

    bion

    Joined:
    Oct 25, 2012
    Posts:
    5
    Hi, now i am using unity4.7.2f1, and now our app have succeed in www and socket fuctions.
    But,in our project we used HttpWebRequest to do file download,and failed.
    The code like follows:

    System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(url);
    System.Net.HttpWebRequest requestGetCount = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(url);
    long countLength = requestGetCount.GetResponse().ContentLength;
    long currentLength = 0;

    url:http://10.2.19.43/Hotupdate/ios/PreBundle_1.zip

    wish you help me.:)
     
  40. bion

    bion

    Joined:
    Oct 25, 2012
    Posts:
    5

    solved it.
    i used dns instead of ip,and it works
     
  41. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    2,756
    @sdfasdf3

    To get another data point, can you try the same C# code that uses Dns.GetHostEntry in a standalone C# application outside of Unity in your testing environment? The behavior of Unity should match that behavior.
     
  42. zzh1234567

    zzh1234567

    Joined:
    Jun 15, 2016
    Posts:
    7
    Do u solve the problem? we have the same problem.
     
  43. zzh1234567

    zzh1234567

    Joined:
    Jun 15, 2016
    Posts:
    7
    @CoS_Ethan
     
  44. mcarriere

    mcarriere

    Joined:
    Sep 14, 2012
    Posts:
    41
    Is there an expected patch release we can keep a look out for? Doesn't seem to be in 5.3.5p1,2 or 3
     
  45. CoS_Ethan

    CoS_Ethan

    Joined:
    Jun 6, 2012
    Posts:
    67
    Not yet, still working on it.
     
  46. zzh1234567

    zzh1234567

    Joined:
    Jun 15, 2016
    Posts:
    7
    The problem dont exist when build with mono as scripting backend . waiting next 4.7.x release
     
  47. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    2,756
    @zzh1234567

    If you're referring to the problem of IPv6 support in the Unity editor on Windows, note that we are not planning to ship a new 4.7 patch release to correct it. We only back ported IPv6 fixes for iOS to 4.7 due to the Apple App Store submission requirements.
     
  48. zzh1234567

    zzh1234567

    Joined:
    Jun 15, 2016
    Posts:
    7
    I got it.we have the problem on ios. my iphone client is build with il2cpp and run in ipv6 nat64/dns64 mac simulation environment. my code enumerate all vaild ip address and family of my ipv4 game server. and try to connect the server with BeginConnect. my client return “An address incompatible with the requested protocol was used” . the same code and network work when i change the build setting to momo backend
     
  49. SenaBlue

    SenaBlue

    Joined:
    Jun 16, 2016
    Posts:
    3
    Hi.

    They were unable to pass through Apple's review.
    Cause is not able to connect with IPv6 only network, was that.
    From Unity4.6.5 to Unity 4.7.2 has been upgraded.

    Has to try to review many times, it can not be seen at all signs of passing.
    There was no problem in the operation check in NAT64 environment that Apple has specified.
    In addition, it does not appear to be environment construction have failed.
    Us white also submit a crash log, and only said no,
    But, however only a resulting normal result, crash log can not be obtained.
     
  50. Nicolas1212

    Nicolas1212

    Joined:
    Dec 18, 2014
    Posts:
    102
    “An address incompatible with the requested protocol was used”

    @zzh1234567 What compatibility level are you using? I found that I got the same error when using ".Net 2.0" but not ".Net 2.0 Subset"