cocos2d-x实战js卷中的socket.io代码不可用

前几天买了本cocos2d-x实战js卷,学习到15章的基于Node.js的Socket.IO网络通信,于是按教材说的方法成功搭建了node.js,安装了Socket.IO模块包(0.9.16版)。接着我到智捷课堂下了对应的服务端可客户端的源码,服务端用dos命令行成功运行,客户端用COCOS IDE生成了工程文件并运行。
NOTICE: Initial logging level 7
NOTICE: Library version: 1.3 unknown-build-hash
NOTICE: IPV6 not compiled in
NOTICE: libev support not compiled in
NOTICE: static allocation: 4464 + (12 x 30000 fds) = 364464 bytes
NOTICE: canonical_hostname = QH-20140114GQHM
NOTICE: per-conn mem: 152 + 1594 headers + protocol rx buf
NOTICE: libwebsocket_context_destroy
Console: listening on 0.0.0.0 : 6050
Console: listening on 0.0.0.0 : 6060
Ready for GLSL
Ready for OpenGL 2.0

{
gl.version: 4.0.0 - Build 9.17.10.2932
gl.supports_NPOT: true
cocos2d.x.version: cocos2d-x 3.5
cocos2d.x.compiled_with_profiler: false
cocos2d.x.build_type: DEBUG
cocos2d.x.compiled_with_gl_state_cache: true
gl.max_texture_size: 8192
gl.vendor: Intel
gl.renderer: Intel® HD Graphics 4000
gl.max_texture_units: 80
gl.supports_ETC1: false
gl.supports_S3TC: true
gl.supports_ATITC: false
gl.supports_PVRTC: false
gl.supports_BGRA8888: false
gl.supports_discard_framebuffer: false
gl.supports_vertex_array_object: true
}

cocos2d: fullPathForFilename: No file found at script/jsb_debugger.jsc. Possible missing file.
cocos2d: fullPathForFilename: No file found at script/debugger/DevToolsUtils.jsc. Possible missing file.
cocos2d: fullPathForFilename: No file found at script/debugger/core/promise.jsc. Possible missing file.
cocos2d: fullPathForFilename: No file found at script/debugger/transport.jsc. Possible missing file.
cocos2d: fullPathForFilename: No file found at script/debugger/actors/root.jsc. Possible missing file.
cocos2d: fullPathForFilename: No file found at script/debugger/actors/script.jsc. Possible missing file.
cocos2d: fullPathForFilename: No file found at script/debugger/main.jsc. Possible missing file.
cocos2d: fullPathForFilename: No file found at script/jsb_boot.jsc. Possible missing file.
JSB SocketIO.connect method called
Calling native SocketIO.connect method
SIOClientImpl::init() successful
SIOClientImpl::handshake() called
SIOClientImpl::handshake() waiting
JSB SocketIO.on method called
JSB SocketIO eventName to: ‘callClientEvent’
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: ‘error’
SIOClientImpl::handshakeResponse() called
handshake completed
response code: 200
SIOClientImpl::handshake() succeeded
SIOClientImpl::handshake() dump data: Hello World

SIOClientImpl::openSocket() called
_host: localhost, _port: 3000, _path: /socket.io/1/websocket/
JSB SocketIO::SIODelegate->onClose method called from native
JSB SocketIO::SIODelegate->fireEventToScript method called from native with name ‘disconnect’ data:

虽然似乎有些文件没有找到,但客户端与服务器端已经成功连接了。
但当我点击发送信息的时候,就报错了
JS: onMenuCallback
JSB SocketIO.send method called
jsb: ERROR: File …\manual\network\jsb_socketio.cpp: Line: 226, Function: js_cocos2dx_SocketIO_send
Invalid Native Object
JS: src/app.js:46:Error: Invalid Native Object
jsb_socketio.cpp应该是cocos自带的,而app.js是我下的服务器端代码
源码如下:
var _sioClient;
var SocketIO = SocketIO || io;

var HelloWorldLayer = cc.Layer.extend({
ctor:function () {
//////////////////////////////
// 1. super init first
this._super();

    /////////////////////////////
    // 2. add a menu item with "X" image, which is clicked to quit the program
    //    you may modify it.
    // ask director the window size
    var size = cc.director.getWinSize();

    var lblSendMsg = new cc.LabelBMFont("Send Message", res.fnt_fnt);        
    var menuItemSendMsg = new cc.MenuItemLabel(lblSendMsg,  this.onMenuCallback, this);

    var mn = new cc.Menu(menuItemSendMsg);
    mn.alignItemsVertically();
    this.addChild(mn);

    _sioClient = SocketIO.connect("http://localhost:3000/");
    _sioClient.tag = "Cocos2d-JS Client1";
    
    //注册服务器端事件
    _sioClient.on("callClientEvent", this.callClientEvent);//触发服务器端的callClientEvent事件,同时客户端执行this.callClientEvent方法
    
    _sioClient.on("connect", function() {
        cc.log("connect called.");
    });        
    _sioClient.on("message", function(data) {
        cc.log(_sioClient.tag + " message received: " + data);
    });        
    _sioClient.on("error", function() {
        cc.log("error called..");
    });

    return true;
},

onMenuCallback:function (sender) {
    cc.log("onMenuCallback");
    //向服务器发出消息
    _sioClient.send("Hello Socket.IO!");//本行报错
    //触发服务器callServerEvent事件
    _sioClient.emit("callServerEvent","{\"message\":\"Hello Server.\"}");
},
//服务器端回调客户端事件
callClientEvent: function(data) {
    var msg = "Server CallBack: "+ _sioClient.tag +  " Data :" + data;
    cc.log(msg);        
}

});

var HelloWorldScene = cc.Scene.extend({
onEnter:function () {
this._super();
var layer = new HelloWorldLayer();
this.addChild(layer);
}
});
我看了一下服务器,一点变化都没有,说明信息并没有发过来。连接应该是正确的,那么就是上面的send出错了,但是错在哪里?app.js中的出错的那一行应该没有语法问题,而jsb_socketio.cpp又是cocos自带的,应该不会有错才对
求大虾解答:3::6::12:

难道是版本问题?我的引擎是cocos3.6,IDE是1.2.0

兜了一大圈,才发现原来使我用错服务端的源码了

您好 你怎么搞的 ,我用socket io 连接自己的node js服务器不成功,连接 tests里面给的服务器地址也不成功,求助啊

这是我运行后的错误信息

JSB SocketIO.connect method called
Calling native SocketIO.connect method
SIOClientImpl::init() successful
SIOClientImpl::handshake() called
SIOClientImpl::handshake() waiting
JSB SocketIO.on method called
JSB SocketIO eventName to: ‘callClientEvent’
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: ‘error’
Curl curl_easy_getinfo failed: No error
SIOClientImpl::handshakeResponse() called
handshake completed
response code: 400
SIOClientImpl::handshake() failed
error buffer:
JSB SocketIO::SIODelegate->onError method called from native with data:
JSB SocketIO::SIODelegate->fireEventToScript method called from native with name ‘error’ data:
JS: error called…

啥意思啊大佬?我也遇到了个这个问题