我正在玩node.js和socket.io-client.我试图连接到一个不存在的通道,以便触发事件'connect_failed'(在https://github.com/LearnBoost/socket.io-client中指定).
但是,我不能让活动工作:
var clientio = require('socket.io-client');
console.log('Trying stuff ...');
// the channel does not exist
var socket = clientio.connect( 'http://localhost:4000/news' );
// I expect this event to be triggered
socket.on('connect_error', function(){
console.log('Connection Failed');
});
socket.on('connect', function(){
console.log('Connected');
});
socket.on('disconnect', function () {
console.log('Disconnected');
});
socket.send('hi there');
Run Code Online (Sandbox Code Playgroud)
如果我执行将会发生这种情况:
$ node tmp_clientio.js
Trying stuff ...
Run Code Online (Sandbox Code Playgroud)
如果连接到不存在的通道,有关如何触发错误的任何想法?
更新:重命名connect_failed为connect_error
node.js ×1