cocos2d-x 3.16版本测试socketio时服务器自动关闭连接

用的3.16版本的cocos2d_tests.xcodeproj,直接改了ip连接我的服务器。
在网上找了一个可以测试socketio的client网址 http://amritb.github.io/socketio-client-tool/#url=d3M6Ly8xMjcuMC4wLjE6NTAwMA==&opt=&events= connect 和 emit 服务器都没问题。

这是点了测试的 open socketio client 的输出:
SIOClientImpl::init() successful
SIOClientImpl::handshake() called
SIOClientImpl::handshake() waiting
2018-01-25 15:10:59.737388+0800 cpp-tests iOS[35662:2739708] Starting to load http://xxx:5000/socket.io/?EIO=2&transport=polling&b64=true
2018-01-25 15:10:59.753904+0800 cpp-tests iOS[35662:2739708] Received response from request to url http://xxx:5000/socket.io/?EIO=2&transport=polling&b64=true
deallocing Action: 0x6040001107d0 - tag: -1061138430
SIOClientImpl::handshakeResponse() called
handshake completed
response code: 200
SIOClientImpl::handshake() succeeded
SIOClientImpl::handshake() dump data: 109:0{“pingInterval”:25000,“pingTimeout”:60000,“upgrades”:[“websocket”],“sid”:“6560567fbd2e4490bcf4502a0615ce2f”}2:40
SIOClientImpl::handshake() Socket.IO 0.9.x detected
SIOClientImpl::openSocket() called
D/WebSocket.cpp (415): WebSocket thread start, helper instance: 0x6000002b09e0
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: ws, host: xxx, port: 5000, path: /socket.io/1/websocket/109
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 (0x7f87b7c13440) Unhandled websocket event: 32
D/WebSocket.cpp (1322): WebSocket (0x7f87b7c13440) Unhandled websocket event: 29
D/WebSocket.cpp (1322): WebSocket (0x7f87b7c13440) Unhandled websocket event: 24
D/WebSocket.cpp (1197): WebSocket (0x7f87b7c13440) onConnectionError, state: 0 …
D/WebSocket.cpp (1226): WebSocket (0x7f87b7c13440) onConnectionClosed, state: 2 …
D/WebSocket.cpp (1256): onConnectionClosed, WebSocket (0x7f87b7c13440) is closing by server.
D/WebSocket.cpp (1279): WebSocket (0x7f87b7c13440) onConnectionClosed DONE!
D/WebSocket.cpp (1322): WebSocket (0x7f87b7c13440) Unhandled websocket event: 45
D/WebSocket.cpp (1322): WebSocket (0x7f87b7c13440) Unhandled websocket event: 33
D/WebSocket.cpp (1226): WebSocket (0x7f87b7c13440) onConnectionClosed, state: 3 …
Websocket error received: 1
SocketIOTest::onClose called
D/WebSocket.cpp (545): In the destructor of WebSocket (0x7f87b7c13440)
D/WebSocket.cpp (565): before join ws thread
D/WebSocket.cpp (167): NOTICE: lws_context_destroy

D/WebSocket.cpp (425): WebSocket thread exit, helper instance: 0x6000002b09e0
D/WebSocket.cpp (567): after join ws thread
In the destructor of EventListener. 0x600000385890

输出我只把ip换成了xxx,其他的都没变

跟了一点代码,发现socketio被解析成0.9版本了是因为收到的握手数据格式不是以"}"结尾的,把if (res.at(res.size() - 1) == ‘}’)改成if (1)依然行不通
(ps. 看代码注释好像0.9版本// sample: 3GYzE9md2Ig-lm3cf8Rv:60:60:websocket,htmlfile,xhr-polling,jsonp-polling,而1.0版本格式是// sample: 97:0{“sid”:“GMkL6lzCmgMvMs9bAAAA”,“upgrades”:[“websocket”],“pingInterval”:25000,“pingTimeout”:60000})

搜遍了全网找不到解决办法。。。。

有人成功用过cocos2d-x的socketio吗?官方能给个说明测试用例的socketio能不能用么?

看了知乎上有人说c++版的客户端只能用node.js写后台。。我用的flask-socketio(python),不知道是不是这个原因联不了啊?

你好,我也遇到了同样的问题,请问解决了吗

遇到了一样的问题,你后来解决了吗

遇到了一样的问题,你后来解决了吗?