@657880970 写道:
你好,先展示我写的代码
helloworld替换onload
onLoad: function() { var that = this; cc.error('websocket init start'); // var ws = new WebSocket("ws://echo.websocket.org"); var ws = new WebSocket("ws://wiw-dev.leanapp.cn"); cc.error('websocket init mid') ws.onopen = function(event) { cc.error("websocket opened."); }; ws.onmessage = function(event) { cc.error("websocket response text msg: " + event.data); that.label.string = JSON.stringify(event.data); }; ws.onerror = function(event) { cc.error("websocket Send Text fired an error"); }; ws.onclose = function(event) { cc.error("websocket instance closed."); }; cc.error('websocket init end') that.scheduleOnce(function() { cc.error("websocket start to send."); if (ws.readyState === WebSocket.OPEN) { cc.error("websocket success to send."); ws.send("[\"hello\", {}]"); } else { cc.error("websocket instance wasn't ready..."); } }, 3); that.label.string = this.text; },
遇到的问题是,在web平台可以正确的建立连接,但是在android平台上无法成功建立连接。但是在android平台上连ws://echo.websocket.org是可以的。郁闷了好久,求大神给个详细的解决方案。
帖子: 1
参与者: 1