COCOS2DX solve the problem of Apple genuine IPv6

Source: Internet
Author: User
Tags host to ip

Apple's official new rules require new apps to support Ipv6-only's network separately.

Specific requirements Link: https://developer.apple.com/library/mac/documentation/NetworkingInternetWeb/Conceptual/ networkingoverview/understandingandpreparingfortheipv6transition/ Understandingandpreparingfortheipv6transition.html#//apple_ref/doc/uid/tp40010220-ch213-sw13

Enthusiastic netizens came to a Chinese version of:

http://kepenj.me/2016/05/22/Supporting-IPv6/

The national demon and three dozen Bones Jing two projects with the COCOS2DX3.0RC version of two years ago, obviously all kinds of unsupported. And we rewrote the socket ourselves, so there are three places to change:

1.curl

At the beginning, I curl up on a new source, replace the old, the result is not.

And then found that there is a LIBCURL.A library to replace. It is also not possible to replace it.

Then you have to take a few versions of the computer to replace, or not.

Finally, there is no way to run to Cocos2d-x official website to see if there is a relevant historical version can try to use. Results see this:

[3.11. 1] Support ipv6-onlynetwork [3.11] Chipmunk upgrade to V7. 0.1 [3.11] JSB uses the new memory model, the JS script does not need to care about the life cycle of the object, the feature is turned off by default [3.11] Curl upgrades to v7.  - [3.11] OpenSSL upgraded to v1. 0 . 2g[3.11] can use Vscode or a new version of the Firefox debug JSB program [3.11] Fully upgrade the WebGL renderer

That is, the official website specifically added multiple versions to solve the problem of this ipv6-only network.

Knowing this is a good idea, download the latest engine directly. Take a library of curl and replace the old project with the source code.

A library there is a problem a little test, the old version of the COCOS2DX only LIBHCURL.A, and the new version is LIBCURL.A, LIBSSL.A, LIBCRYPTO.A, three are added, but also add to the project reference.

2.host to IP
Domain-to-IP conversion.

Our server is configured with a domain name, and then the client to connect the time, the first domain-to-IP conversion. Then use IP to connect to the server.

Originally we used gethostbyname method to get IPv4 IP. The above link has mentioned this problem, IPv6 to use gethostbyname2.

Also did a try, really C language level is limited, and also do not know how to judge the network is IPv4 or IPv6 problem.

Finally found another domain name conversion IP method. is to use getaddrinfo, the advantage of this method is that it solves the conversion IP, and solves the Judgment network.

This is the OC code.

-(NSString *) Getipwithhostname: (ConstNSString *) HostName {structAddrinfo *result; structAddrinfo *Res; Charipv4[ -]; Charipv6[ -]; interror; BOOL Is_ipv6=FALSE; Bzero (&ipv4,sizeof(IPv4)); Bzero (&ipv4,sizeof(IPv6)); Error= Getaddrinfo ([hostName utf8string], NULL, NULL, &result); if(Error! =0) {NSLog (@"Error in getaddrinfo:%d", error); returnNil; }     for(res = result; res!=null; res = res->Ai_next) {        Charhostname[1025] =""; Error= Getnameinfo (res->ai_addr, Res->ai_addrlen, hostname,1025Null0,0); if(Error! =0) {NSLog (@"error in Getnameifno:%s", Gai_strerror (Error)); Continue; }        Else {            Switch(res->ai_addr->sa_family) {                 Caseaf_inet:memcpy (IPv4, hostname, -);  Break;  Caseaf_inet6:memcpy (IPv6, hostname, -); Is_ipv6=TRUE; default:                     Break; } NSLog (@"hostname:%s", hostname);    }} freeaddrinfo (Result); if(Is_ipv6 = = TRUE)return[NSString Stringwithutf8string:ipv6]; return[NSString Stringwithutf8string:ipv4];}

3.socket

IPv6 inside, the socket creation and connection need to have related changes.

Thank you for the solution.

http://blog.csdn.net/hepeng597/article/details/7803277

Follow the above link to the comparison method, the socket can be modified.

Here is a little trick, if you need to make a network judgment of the connection address, you can determine whether the IP address has a colon ":"

The C language can be used to judge STRCHR (server, ': ')! = NULL

COCOS2DX solve the problem of Apple genuine IPv6

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.