Supporting IPv6-only Networks

As apple required to support IPv6-only Networks since June 1, 2016. So we need to make sure cocos2d-x can work on IPv6-only Networks. And i created an issue for it.

We will fix the issue ASAP. But you are appreciated if you guys can help to test and review the codes. About how to test IPv6 compatibility can refer to the apple doc.

It is better to add a comment to the issue above if you find any problem.

Thanks.

Interesting. Does cocos2d::network::HttpClient support ipv6? I use it and download some content using url (not ip).

@piotrros i don’t know currently, i will do test. And you are appreciated if you can help to test it too.

@zhangxm
I have just confirmed that the latest Cocos2d-x v3.11 works properly with IPV6.

What did I do is using Cocos2d-x’s HttpClint to establish a connection with “ipv6.google.com”, and it turned out fine.

However, when I did the same thing by using the previous version of Cocos2d-x, like v3.8.1, v3.4, v3.3, v3.2, I got a failure.

So in short, I believe Cocos2d-x v3.11 is ready for IPV6.

@zhangleipku1 thanks for testing. I am not sure if connecting with ipv6.google.com can be used for testing IPv6-only compatibility or not. But the the apple doc provide a way to test. And i just tested as the doc said, HttpClient works as expected.

What about 3.10?

Before v3.10, HttpClient on iOS depends on libcurl, and libcurl shift with cocos2d-x supports IPv6 until v3.10.

@makalele i think v3.10 is ok as i said above.

Hi all,

The status of this task is:

  • it is finished for v3
  • v2 is fixed except of windows and wp8, has compiling error on these two platforms because of upgrading libwebsockets. Will support them ASAP.

How to do

You can just update libwebsockets and CURL like this:

  • modify Cocos2d-x root/external/config.json to update the dependency version. For v3.x the dependency version is v3-deps-94, and for v2.x it is v2-deps-6
  • execute the download-deps.py script in your Cocos2d-x root.

Edit: i also modify Console and ScriptingCore to support IPv6-only network in this PR, but i think it is not needed for you to do like this because they are just for testing, not be used in game logic.

If you are using v2.x, you also need to apply this commit to fix compiling error.

Edit: windows compiling issue of v2 is fixed, you need to download v2-deps-v7 instead if you work on windows. And you may need to link ws2_32.lib in libexternal project. Refer to this commit for detail information.

Hi zhangxm

Thank you, but I’m using cocos2dx v2.2.2.

Cocos2d-x root/external/config.json and download-deps.py scripts don’t exist in v2.2.2.
Please tell me what to do, to update libwebsockets and CURL in cocos2dx v2.2.2.

Thank you.

@jamjamcat you can download it here.

1 Like

@zhangxm

I’m using Cocos2d-JS v3.8.1 with Cocos.

To solve this problem, i only need to update libwebsockets and CURL which can download from link below?

As i checked this issue on GitHub.


3rd party libraries supports IPv6-only networks

 CURL
 websocket

cocos2d-x provided network modules support IPv6-only networks

 HttpClient
 AssetsManagerEx
 SocketIO
 WebSocket
 Console
 ScriptingCore

Does update libwebsockets and CURL will solved the network modules provided by cocos2d-x?
I’m using AssetsManagerEx, how can i update those modules?

Thank you.

Yep, updatelibwebsockets and CURL can resolve it. Console and ScriptingCore related codes are just for debug purpose, so you don’t have to care about it.

@zhangxm

So i just need to replace the libwebsockets and CURL folder in external folder?

But i can’t rebuild the library, got error on WebSocket.cpp

The following build commands failed: CompileC build/cocos2d_libs.build/Release-iphonesimulator/libcocos2d\ iOS.build/Objects-normal/i386/WebSocket.o /Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.cpp normal i386 c++ com.apple.compilers.llvm.clang.1_0.compiler

/Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.cpp:104:38: error: ISO C++
      forbids forward references to 'enum' types
                                enum libwebsocket_callback_reasons reason,
                                     ^
/Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.cpp:104:68: error: variable has
      incomplete type 'enum libwebsocket_callback_reasons'
                                enum libwebsocket_callback_reasons reason,
                                                                   ^
/Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.cpp:104:38: note: forward
      declaration of 'cocos2d::network::libwebsocket_callback_reasons'
                                enum libwebsocket_callback_reasons reason,
                                     ^
/Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.cpp:108:45: error: use of
      undeclared identifier 'libwebsocket_context_user'
        WebSocket* wsInstance = (WebSocket*)libwebsocket_context_user(ctx);
                                            ^
/Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.cpp:251:33: error: subscript of
      pointer to incomplete type 'struct libwebsocket_protocols'
    for (int i = 0; _wsProtocols[i].callback != nullptr; ++i)
                    ~~~~~~~~~~~~^
In file included from /Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.cpp:30:
/Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.h:41:8: note: forward
      declaration of 'libwebsocket_protocols'
struct libwebsocket_protocols;
       ^
/Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.cpp:253:42: error: subscript of
      pointer to incomplete type 'struct libwebsocket_protocols'
        CC_SAFE_DELETE_ARRAY(_wsProtocols[i].name);
                             ~~~~~~~~~~~~^
In file included from /Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.cpp:30:
In file included from /Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.h:36:
/Applications/Cocos/frameworks/cocos2d-x-3.8.1/build/../cocos/platform/CCPlatformMacros.h:215:45: note: 
      expanded from macro 'CC_SAFE_DELETE_ARRAY'
#define CC_SAFE_DELETE_ARRAY(p)     do { if(p) { delete[] (p); (p) = nullptr; } } while(0)
                                            ^
In file included from /Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.cpp:30:
/Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.h:41:8: note: forward
      declaration of 'libwebsocket_protocols'
struct libwebsocket_protocols;
       ^
/Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.cpp:253:42: error: subscript of
      pointer to incomplete type 'struct libwebsocket_protocols'
        CC_SAFE_DELETE_ARRAY(_wsProtocols[i].name);
                             ~~~~~~~~~~~~^
In file included from /Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.cpp:30:
In file included from /Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.h:36:
/Applications/Cocos/frameworks/cocos2d-x-3.8.1/build/../cocos/platform/CCPlatformMacros.h:215:60: note: 
      expanded from macro 'CC_SAFE_DELETE_ARRAY'
#define CC_SAFE_DELETE_ARRAY(p)     do { if(p) { delete[] (p); (p) = nullptr; } } while(0)
                                                           ^
In file included from /Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.cpp:30:
/Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.h:41:8: note: forward
      declaration of 'libwebsocket_protocols'
struct libwebsocket_protocols;
       ^
/Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.cpp:253:42: error: subscript of
      pointer to incomplete type 'struct libwebsocket_protocols'
        CC_SAFE_DELETE_ARRAY(_wsProtocols[i].name);
                             ~~~~~~~~~~~~^
In file included from /Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.cpp:30:
In file included from /Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.h:36:
/Applications/Cocos/frameworks/cocos2d-x-3.8.1/build/../cocos/platform/CCPlatformMacros.h:215:65: note: 
      expanded from macro 'CC_SAFE_DELETE_ARRAY'
#define CC_SAFE_DELETE_ARRAY(p)     do { if(p) { delete[] (p); (p) = nullptr; } } while(0)
                                                                ^
In file included from /Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.cpp:30:
/Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.h:41:8: note: forward
      declaration of 'libwebsocket_protocols'
struct libwebsocket_protocols;
       ^
/Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.cpp:255:2: warning: deleting
      pointer to incomplete type 'struct libwebsocket_protocols' may cause undefined behavior
      [-Wdelete-incomplete]
        CC_SAFE_DELETE_ARRAY(_wsProtocols);
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.cpp:30:
In file included from /Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.h:36:
/Applications/Cocos/frameworks/cocos2d-x-3.8.1/build/../cocos/platform/CCPlatformMacros.h:215:50: note: 
      expanded from macro 'CC_SAFE_DELETE_ARRAY'
#define CC_SAFE_DELETE_ARRAY(p)     do { if(p) { delete[] (p); (p) = nullptr; } } while(0)
                                                 ^        ~~~
In file included from /Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.cpp:30:
/Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.h:41:8: note: forward
      declaration of 'libwebsocket_protocols'
struct libwebsocket_protocols;
       ^
/Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.cpp:312:21: error: allocation of
      incomplete type 'libwebsocket_protocols'
        _wsProtocols = new libwebsocket_protocols[protocolCount+1];
                           ^~~~~~~~~~~~~~~~~~~~~~
In file included from /Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.cpp:30:
/Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.h:41:8: note: forward
      declaration of 'libwebsocket_protocols'
struct libwebsocket_protocols;
       ^
/Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.cpp:313:26: error: invalid
      application of 'sizeof' to an incomplete type 'libwebsocket_protocols'
        memset(_wsProtocols, 0, sizeof(libwebsocket_protocols)*(protocolCount+1));
                                ^     ~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.cpp:30:
/Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.h:41:8: note: forward
      declaration of 'libwebsocket_protocols'
struct libwebsocket_protocols;
       ^
/Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.cpp:322:25: error: subscript of
      pointer to incomplete type 'struct libwebsocket_protocols'
            _wsProtocols[i].name = name;
            ~~~~~~~~~~~~^
In file included from /Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.cpp:30:
/Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.h:41:8: note: forward
      declaration of 'libwebsocket_protocols'
struct libwebsocket_protocols;
       ^
/Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.cpp:323:25: error: subscript of
      pointer to incomplete type 'struct libwebsocket_protocols'
            _wsProtocols[i].callback = WebSocketCallbackWrapper::onSocketCallback;
            ~~~~~~~~~~~~^
In file included from /Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.cpp:30:
/Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.h:41:8: note: forward
      declaration of 'libwebsocket_protocols'
struct libwebsocket_protocols;
       ^
/Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.cpp:330:21: error: subscript of
      pointer to incomplete type 'struct libwebsocket_protocols'
        _wsProtocols[0].name = name;
        ~~~~~~~~~~~~^
In file included from /Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.cpp:30:
/Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.h:41:8: note: forward
      declaration of 'libwebsocket_protocols'
struct libwebsocket_protocols;
       ^
/Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.cpp:331:21: error: subscript of
      pointer to incomplete type 'struct libwebsocket_protocols'
        _wsProtocols[0].callback = WebSocketCallbackWrapper::onSocketCallback;
        ~~~~~~~~~~~~^
In file included from /Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.cpp:30:
/Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.h:41:8: note: forward
      declaration of 'libwebsocket_protocols'
struct libwebsocket_protocols;
       ^
/Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.cpp:403:9: error: use of
      undeclared identifier 'libwebsocket_context_destroy'; did you mean 'lws_context_destroy'?
        libwebsocket_context_destroy(_wsContext);
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
        lws_context_destroy
In file included from /Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.cpp:41:
/Applications/Cocos/frameworks/cocos2d-x-3.8.1/build/../external/websockets/include/ios/libwebsockets.h:1398:1: note: 
      'lws_context_destroy' declared here
lws_context_destroy(struct lws_context *context);
^
/Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.cpp:403:38: error: cannot
      initialize a parameter of type 'struct lws_context *' with an lvalue of type
      'struct libwebsocket_context *'
        libwebsocket_context_destroy(_wsContext);
                                     ^~~~~~~~~~
In file included from /Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.cpp:41:
/Applications/Cocos/frameworks/cocos2d-x-3.8.1/build/../external/websockets/include/ios/libwebsockets.h:1398:41: note: 
      passing argument to parameter 'context' here
lws_context_destroy(struct lws_context *context);
                                        ^
/Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.cpp:410:9: error: use of
      undeclared identifier 'libwebsocket_service'
        libwebsocket_service(_wsContext, 0);
        ^
/Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.cpp:434:17: error: assigning to
      'const struct lws_protocols *' from incompatible type 'struct libwebsocket_protocols *'
        info.protocols = _wsProtocols;
                       ^ ~~~~~~~~~~~~
/Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.cpp:436:20: error: use of
      undeclared identifier 'libwebsocket_get_internal_extensions'
        info.extensions = libwebsocket_get_internal_extensions();
                          ^
/Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.cpp:442:15: error: use of
      undeclared identifier 'libwebsocket_create_context'; did you mean 'lws_create_context'?
        _wsContext = libwebsocket_create_context(&info);
                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~
                     lws_create_context
In file included from /Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.cpp:41:
/Applications/Cocos/frameworks/cocos2d-x-3.8.1/build/../external/websockets/include/ios/libwebsockets.h:1392:1: note: 
      'lws_create_context' declared here
lws_create_context(struct lws_context_creation_info *info);
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
1 warning and 20 errors generated.

@Zinitter It is because libwebsockets breaks compatibility. You can refer to this commit to modify corresponding codes.

@zhangxm

Thanks for your reply.

I have replaced WebSocket.cpp and WebSocket.h but there is error on lua-bindings.

I think it would have error on js-bindings too as you said it breaks compatibility.

Any solution?

In file included from /Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/scripting/lua-bindings/manual/network/Lua_web_socket.h:37:
/Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/scripting/lua-bindings/proj.ios_mac/../../../network/WebSocket.h:37:10: fatal error: 
      'libwebsockets.h' file not found
#include "libwebsockets.h"
         ^
1 error generated.

@Zinitter I am not sure if you can just replace the files. But modification is for v2.x, i think you can just refer to the modification.

@zhangxm

I have tried replace and modification, both have same issue when running cocos gen-libs.

@zhangxm

I try to generate libjscocos2d but got this error on enum lws_callback_reasons reason of Websocket.h

Before modification, it is int instead of enum.

ISO C++ forbids forward references to 'enum' types

int onSocketCallback(struct lws *wsi,
                         enum lws_callback_reasons reason,
                         void *user, void *in, size_t len);

Yep, you should modify the codes according new libwebsockets.