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();
// });
}

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM