cocos2d-x3.10 适配 IPV6

cocos 依赖的三方库涉及到 IPV6 问题的库为 curlwebsocket, cocos 自己提供的模块需要适配的有:

  1. HttpClient
  2. AssetsManagerEx
  3. SocketIO
  4. WebSocket
  5. Console
  6. ScriptingCore

如果你需要支持纯IPv6网络,只需要更新CURL和libwebsocket网络。

1. 下载 cocos2d-x-3rd-party-libs-bin

2. 更新 curl

拷贝解压出来的文件夹中的 curl 目录到cocos2d-x/external, 替换原来的 curl目录. 如果编译报错,则:

在 XCode 项目输找到 cocos2d_lib > external > curl > ios 目录上右键, 选择 Add Files to 'cocos2d_lib.xcodeproj':

image_1alkfv73t446cr3sc41r6r1hqj13.png-238.8kB

选中 libcrypto.a 和 libssl.a, targets 选择 libcocos2d iOS, 确定, 重新编译, 搞定.

3. 更新 websocket

和 curl 类似, 拷贝 cocos2d-x-3rd-party-libs 中的 websockets 目录到 cocos2d-x/external, 替换原来的 websockets 目录.

因为最新版的 websockets api 变化挺大, 所以我们需要使用 cocos 最新的WebSocket.h 和 WebSocket.cpp 替换 cocos2d-x/cocos/network 中的 WebSocket .

编译, 会有一处错误发生在 WebSocket::WebSocket() 中, 是和 Director::EVENT_RESET 相关的消息, 我们注释掉这段代码即可.

{
// reserve data buffer to avoid allocate memory frequently
_receivedData.reserve(WS_RESERVE_RECEIVE_BUFFER_SIZE);
if (__websocketInstances == nullptr)
{
__websocketInstances = new (std::nothrow) std::vector<WebSocket*>();
}

__websocketInstances->push_back(this);

// std::shared_ptr<std::atomic<bool>> isDestroyed = _isDestroyed;
// _resetDirectorListener = Director::getInstance()->getEventDispatcher()->addCustomEventListener(Director::EVENT_RESET, [this, isDestroyed](EventCustom*){
// if (*isDestroyed)
// return;
// close();
// });
}

 

 

posted @ 2017-04-23 11:03  关懿  阅读(1543)  评论(0编辑  收藏  举报