模拟器运行没问题打包闪退, 大概在HttpClientHttpResponseEPc

而且很奇怪我用curl直接访问网址是可以正常返回200的,就是这样:

curl http://mydomain:80/socket.io/1/?EIO=2&transport=polling&b64=true

我看代码里用了NSURLConnection来请求,就返回404了,好奇怪

嗯,的确,curl是可以正常的。这个原因还是不明。
但是就你的服务器,如果加上强制写了端口80,NSURLConnection就是访问不了,其他的网站没问题。麻烦帮忙确认下,服务端做了什么特殊处理么?


{
	gl.supports_OES_map_buffer: false
	gl.supports_vertex_array_object: true
	cocos2d.x.version: 1.4.0-lite
	gl.vendor: NVIDIA Corporation
	gl.supports_PVRTC: false
	gl.renderer: NVIDIA GeForce GT 650M OpenGL Engine
	cocos2d.x.compiled_with_profiler: false
	gl.max_texture_size: 16384
	gl.supports_ETC1: false
	gl.supports_BGRA8888: false
	cocos2d.x.build_type: DEBUG
	gl.max_texture_units: 16
	gl.supports_OES_packed_depth_stencil: false
	gl.supports_discard_framebuffer: false
	gl.supports_NPOT: true
	gl.version: 2.1 NVIDIA-10.14.20 355.10.05.15f03
	cocos2d.x.compiled_with_gl_state_cache: true
	gl.supports_OES_depth24: false
}


cocos2d: warning, Director::setProjection() failed because size is 0
cocos2d: fullPathForFilename: No file found at script/jsb_prepare.jsc. Possible missing file.
cocos2d: fullPathForFilename: No file found at script/jsb_boot.jsc. Possible missing file.
Cocos2d-JS v3.14
libpng warning: iCCP: known incorrect sRGB profile
Success to load scene: db://assets/Scene/helloworld.fire
JSB SocketIO.connect method called
Calling native SocketIO.connect method
SIOClientImpl::init() successful
SIOClientImpl::handshake() called
SIOClientImpl::handshake() waiting
In the constructor of HttpClient!
JSB SocketIO.on method called
JSB SocketIO eventName to: 'connect'
JSB SocketIO.on method called
JSB SocketIO eventName to: 'message'
JSB SocketIO.on method called
JSB SocketIO eventName to: 'disconnect'
2017-02-23 14:13:07.798596 hello_world-desktop[53224:32246545] Port: 0
2017-02-23 14:13:07.976399 hello_world-desktop[53224:32246545] statusCode = 200
2017-02-23 14:13:07.976578 hello_world-desktop[53224:32246545] Starting to load http://xxx.com/socket.io/1/?EIO=2&transport=polling&b64=true
2017-02-23 14:13:08.027992 hello_world-desktop[53224:32246545] Received response from request to url http://xxx.com/socket.io/1/?EIO=2&transport=polling&b64=true
SIOClientImpl::handshakeResponse() called
handshake completed
response code: 200
SIOClientImpl::handshake() succeeded
SIOClientImpl::handshake() dump data: 97:0{"sid":"3GKYPOGlikp5y_ZmAAC2","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":60000}
SIOClientImpl::handshake() Socket.IO 1.x detected
done parsing 1.x
SIOClientImpl::openSocket() called
[WebSocket::init] _host: xxx.com, _port: 80, _path: /socket.io/1/websocket/?EIO=2&transport=websocket&sid=3GKYPOGlikp5y_ZmAAC2
WebSocket thread start, helper instance: 0x6100000ac000
NOTICE: Initial logging level 967

NOTICE: Libwebsockets version: 1.7.8 linwenhai@LindeMacBook-Pro.local-v3.4-49-g9369eea

NOTICE: IPV6 compiled in and enabled

NOTICE: libev support not compiled in

NOTICE:  Threads: 1 each 7168 fds

NOTICE:  mem: platform fd map: 57344 bytes

NOTICE:  mem: per-conn:          368 bytes + protocol rx buf

NOTICE: wsi 0x104846210: TIMEDOUT WAITING on 4 (did hdr 0, ah 0x105195000, wl 0, pfd events 0)

WebSocket (0x6100001c5820) onConnectionError ...
NOTICE: lws_header_table_detach: wsi 0x104846210: ah held 21s, ah.rxpos 0, ah.rxlen 0, mode/state 13 4,wsi->more_rx_waiting 0

Ready state is closing or was closed, code=2, quit websocket thread!
NOTICE: lws_context_destroy

WebSocket (0x6100001c5820) onConnectionClosed ...
WebSocket thread exit, helper instance: 0x6100000ac000
Websocket error received: 1
JSB SocketIO::SIODelegate->onClose method called from native
JSB SocketIO::SIODelegate->fireEventToScript method called from native with name 'disconnect' data: 
In the destructor of WebSocket (0x6100001c5820)

这是我在mac运行的日志,libwebsockets这个C库返回了超时。。。

@avatar, 你服务端用的socketio的版本是多少?

服务器用的leancloud, 这么配置的: “socket.io”: “^1.7.1”, 应该是1.7.1往上的版本

还真没做什么特殊处理,相同的代码,我在本地开服务器,用设备连接本地电脑的3000端口,正常…

我对nodejs不熟悉,^表示往上?看这个应该是比较新的版本。

嗯是的, 1.x.x版本中会找一个最新的

又有一些进展,我用iocat可以正常连接:
iocat -v --socketio http://xxx.com:80/socket.io/1/?EIO=2&transport=polling&b64=true

但是通过ios native连就返回400, 是不是说明还是跟客户端有关系?

哎,自己重新编译websocket库终于找出问题原因了… 这地方前前后后踩了三个坑,其中一个坑之前用lua的时候就遇到过,我还提交了pull request, 直接导致握手触发onConnectionClosed …
现在jsb里面还存在… 好像只有我遇到… 别人都没事…

什么坑?能够分享一下解决方案么?

这个问题我之前其实提交过pull request的, 但是因为不明原因,其他人也没提过, 所以没有合并进去,只能假设大家都没问题了. 我那个修复是有点quick and dirty…

先不多说了,有人遇到了来找我,必定分享.

pull request的链接发一下吧,谢谢。

私信你了

大神求链接!!我现在重连就会一直调用onConnectionClosed …,连接不上服务器

加我QQ吧, 我踩了至少两个坑,要问下你遇到的具体情况… 1676六四零四

cocos creator 1.4.2 使用websocket,也碰到相同问题了。

简单的一个connect :this._sock = new WebSocket(NetConfig.Server.host + “:” + NetConfig.Server.port);
web测试没问题,在ios模拟器运行就断开连接,求分享解决方案

NOTICE: Initial logging level 967

NOTICE: Libwebsockets version: 1.7.8 linwenhai@LindeMacBook-Pro.local-v3.4-49-g9369eea

NOTICE: IPV6 compiled in and enabled

NOTICE: libev support not compiled in

NOTICE: Threads: 1 each 256 fds

NOTICE: mem: platform fd map: 2048 bytes

NOTICE: mem: per-conn: 368 bytes + protocol rx buf

NOTICE: wsi 0x7ff7c66475e0: TIMEDOUT WAITING on 4 (did hdr 0, ah 0x7ff7ca0e3e00, wl 0, pfd events 0)

WebSocket (0x6100001ca230) onConnectionError …
NOTICE: lws_header_table_detach: wsi 0x7ff7c66475e0: ah held 22s, ah.rxpos 0, ah.rxlen 0, mode/state 13 4,wsi->more_rx_waiting 0

Ready state is closing or was closed, code=2, quit websocket thread!
NOTICE: lws_context_destroy

WebSocket (0x6100001ca230) onConnectionClosed …
WebSocket thread exit, helper instance: 0x6180000b7ac0
**** /build/jsb-default/frameworks/cocos2d-x/cocos/scripting/js-bindings/script/jsb_boot.js:741:TypeError: ‘prototype’ property of fNOP is not an object

In the destructor of WebSocket (0x6100001ca230)