@麒麟子 大神关注下
#问题所在
cocos creator ver: 1.5.1 beta4
刚打算用cocos creator开发游戏,由于苹果审核原因,所以,也采用了https和wss。
目前基于PC浏览器,一切正常。测试ios和android原生打包报错。
求官方或大神帮帮忙~
下面是错误信息,其中的域名
,我已经马赛克
了。
connect to wss://www.abc.com:12345
D/WebSocket.cpp (415): WebSocket thread start, helper instance: 0x6080000b0620
D/WebSocket.cpp (167): NOTICE: Initial logging level 911
D/WebSocket.cpp (167): NOTICE: Libwebsockets version: 2.1.0 james@James-Chen.local-v3.4-139-gbdcf7f8
D/WebSocket.cpp (167): NOTICE: IPV6 compiled in and enabled
D/WebSocket.cpp (167): NOTICE: libev support not compiled in
D/WebSocket.cpp (167): NOTICE: libuv support not compiled in
D/WebSocket.cpp (167): NOTICE: Threads: 1 each 2560 fds
D/WebSocket.cpp (167): NOTICE: mem: platform fd map: 20480 bytes
D/WebSocket.cpp (167): NOTICE: Compiled with OpenSSL support
D/WebSocket.cpp (167): NOTICE: mem: per-conn: 512 bytes + protocol rx buf
D/WebSocket.cpp (873): scheme: wss, host: abc.com, port: 12345, path:
D/WebSocket.cpp (837): WARNING: CA Root file isn’t set. SSL connection will not peer server certificate
D/WebSocket.cpp (167): NOTICE: Creating Vhost ‘default’ port -1, 1 protocols, IPv6 on
D/WebSocket.cpp (167): NOTICE: lws_protocol_init
D/WebSocket.cpp (1322): WebSocket (0x7ffabf5725e0) Unhandled websocket event: 32
D/WebSocket.cpp (1322): WebSocket (0x7ffabf5725e0) Unhandled websocket event: 29
D/WebSocket.cpp (167): ERR: server’s cert didn’t look good, X509_V_ERR = 20: error:00000014:lib(0):func(0):reason(20)
D/WebSocket.cpp (1197): WebSocket (0x7ffabf5725e0) onConnectionError, state: 0 …
D/WebSocket.cpp (1226): WebSocket (0x7ffabf5725e0) onConnectionClosed, state: 2 …
D/WebSocket.cpp (1256): onConnectionClosed, WebSocket (0x7ffabf5725e0) is closing by server.
#参考提供的解决方案
参考提供了cocos-x的解决方案,需要设定CA根证书即可,但在creator里,如何去设置呢?
参考url:http://discuss.cocos2d-x.org/t/websocket-supports-ssl-connections/34611
auto ws = new WebSocket();
ws->init("wss://echo.websocket.org", nullptr, "your CA root file path");
#补充
在cocos-x中 jsb_websocket.cpp
看到有这样的映射方法:
可以在第3个参数设置根证书。
(据我初步了解jsb,应该是cocos creator原生app专用接口,我们项目即需要H5,也需要原生app)
…
310 bool js_cocos2dx_extension_WebSocket_constructor(JSContext *cx, uint32_t argc, jsval vp)
…
373 cobj = new (std::nothrow) WebSocket();
374 JSB_WebSocketDelegate delegate = new (std::nothrow) JSB_WebSocketDelegate();
375 delegate->setJSDelegate(obj);
376 cobj->init(*delegate, url, &protocols, caFilePath);