Supporting IPv6-only Networks

Supporting IPv6-only Networks
0

#4

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


#5

@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.


#6

@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.


#7

What about 3.10?


#8

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.


#9

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.


#10

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.


#11

@jamjamcat you can download it here.


#12

@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.


#13

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.


#14

@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.

#15

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


#16

@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.

#17

@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.


#18

@zhangxm

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


#19

@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);

#20

Yep, you should modify the codes according new libwebsockets.


#21

@zhangxm

After adding #include "external/websockets/include/ios/libwebsockets.h" to WebSocket.h, i can build libjscocos2d.

But new errors occur when running cocos gen-libs

/Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.cpp:473:16: error: out-of-line definition of
      'onSocketCallback' does not match any declaration in 'cocos2d::network::WebSocket'
int WebSocket::onSocketCallback(struct lws *wsi,
               ^~~~~~~~~~~~~~~~
/Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.cpp:562:23: error: assigning to
      'enum lws_write_protocol' from incompatible type 'int'
                                                                writeProtocol |= LWS_WRITE_NO_FIN;
                                                                              ^  ~~~~~~~~~~~~~~~~
/Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.cpp:568:41: error: assigning to
      'enum lws_write_protocol' from incompatible type 'int'
                                        writeProtocol |= LWS_WRITE_NO_FIN;
                                                      ^  ~~~~~~~~~~~~~~~~
/Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/network/WebSocket.cpp:642:44: error: use of undeclared identifier
      'libwebsockets_remaining_packet_payload'; did you mean 'lws_remaining_packet_payload'?
                    _pendingFrameDataLen = libwebsockets_remaining_packet_payload (wsi);
                                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                           lws_remaining_packet_payload
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:45:
/Applications/Cocos/frameworks/cocos2d-x-3.8.1/build/../external/websockets/include/ios/libwebsockets.h:1613:1: note: 
      'lws_remaining_packet_payload' declared here
lws_remaining_packet_payload(struct lws *wsi);
^
4 errors generated.

It there any guide on how to solve IPv6 for Cocos2d-JS v3.8.1?


#22

@Zinitter I think you need to re-generate binding codes by run cocos2dx_root/tools/tojs/genbindings.py. And you can refer to this repo to set up environment if you meet any problem.


#23

@zhangxm

I have run genbindings.py but the issue still occur.

Generating javascript bindings succeeds 

I think there is issue on the manual bindings on path
/Applications/Cocos/frameworks/cocos2d-x-3.8.1/cocos/scripting/js-bindings/manual/network/jsb_websocket.cpp

which won’t auto generated by the script.