@run2080 写道:
直接新建 一个 Hello Word 工程
// var GSocket = null;cc.Class({
extends: cc.Component,properties: { label: { default: null, type: cc.Label }, // defaults, set visually when attaching this script to the Canvas text: 'Hello, World!' }, // use this for initialization onLoad: function () { this.label.string = this.text; // GSocket = new WebSocket("ws://192.168.1.131:8400"); this.GSocket = new WebSocket("ws://192.168.1.131:8400"); // GSocket.onopen = function (event) { this.GSocket.onopen = function (event) { console.log("onopen"); }; // GSocket.onerror = function (event) { this.GSocket.onerror = function (event) { console.log("-------------onerror"); }; // GSocket.onclose = function (event) { this.GSocket.onclose = function (event) { console.log("---------------onclose"); }; // GSocket.onmessage = function (event) { this.GSocket.onmessage = function (event) { console.log("onmessage"); }; }, // called every frame update: function (dt) { },
});
浏览器运行 没问题 模拟器运行 出错 Log如下
2016-12-22T12:44:42.492Z - normal: Simulator: Cocos2d-JS v3.132016-12-22T12:44:42.528Z - normal: Simulator: iShow!
2016-12-22T12:44:42.609Z - normal: Simulator: [WebSocket::init] _host: 192.168.1.131, _port: 8400, _path: /
2016-12-22T12:44:42.609Z - normal: Simulator: WebSocket thread start, helper instance: 0974AA80
2016-12-22T12:44:42.609Z - normal: Simulator: NOTICE: Initial logging level 967
2016-12-22T12:44:42.609Z - normal: Simulator:
2016-12-22T12:44:42.610Z - normal: Simulator: NOTICE: Libwebsockets version: 1.6.0 unknown-build-hash
2016-12-22T12:44:42.610Z - normal: Simulator:
2016-12-22T12:44:42.610Z - normal: Simulator: NOTICE: IPV6 not compiled in
2016-12-22T12:44:42.610Z - normal: Simulator:
2016-12-22T12:44:42.610Z - normal: Simulator: NOTICE: libev support not compiled in
2016-12-22T12:44:42.610Z - normal: Simulator:
2016-12-22T12:44:42.610Z - normal: Simulator: NOTICE: mem: per-conn: 280 bytes + protocol rx buf
2016-12-22T12:44:42.610Z - normal: Simulator:
2016-12-22T12:44:42.611Z - normal: Simulator: WebSocket (09283390) onConnectionError ...
2016-12-22T12:44:42.611Z - normal: Simulator: Ready state is closing or was closed, code=2, quit websocket thread!
2016-12-22T12:44:42.611Z - normal: Simulator: NOTICE: lws_context_destroy
2016-12-22T12:44:42.611Z - normal: Simulator:
2016-12-22T12:44:42.611Z - normal: Simulator: WebSocket (09283390) onConnectionClosed ...
2016-12-22T12:44:42.611Z - normal: Simulator: WebSocket thread exit, helper instance: 0974AA80
2016-12-22T12:44:42.611Z - normal: Simulator: -------------onerror
2016-12-22T12:44:42.611Z - normal: Simulator: ---------------onclose
2016-12-22T12:44:45.173Z - normal: Simulator: In the destructor of WebSocket (09283390)
2016-12-22T12:44:45.174Z - normal: Simulator: basic_object_finalize 07D315C0 ...
2016-12-22T12:44:45.175Z - normal: Simulator: jsbindings: finalizing JS object 07D315E0 (WebSocket)
2016-12-22T12:44:45.175Z - normal: Simulator: jsbindings: finalizing JS object 07D31600 (SocketIO)
2016-12-22T12:44:45.175Z - normal: Simulator: jsbindings: finalizing JS object 07D31A20 (WebSocket)
帖子: 1
参与者: 1