在node.connect()到irc.freenode.net之后连接断开连接

时间:2015-05-11 01:07:59

标签: node.js

我已经连接到irc了。但连接后,它立即断开连接,没有任何错误信息。怎么会发生这种情况?

IRC日志:

straysh (~mynick@li760-156.members.linode.com) has joined #Node.js
straysh has quit (Remote host closed the connection)

我的控制台日志:

straysh IRC-client]$node index.js
Established connection, registering and shit...
straysh IRC-client]$

这是我的代码:

/**
 * Module Dependencies
 */

try{
    var net= require('net');
    var client = net.connect(6667, 'irc.freenode.net');
    client.setEncoding('utf8');
    client.setKeepAlive(true);
    client.on('error', function(err){
        console.log(err);
    });
    client.on('close', function(has_err){
        console.log('connection gone...');
        console.log(has_err);
   });
    client.on('connect', function(){
        console.log('Established connection, registering and shit...');
        setTimeout(function(){
            client.write('NICK straysh\r\n');
            client.write('USER mynick 0 * :realname\r\n');
            client.write('JOIN #node.js\r\n');
        }, 1000);
    });
}catch( e ){
    console.log(e);
}

0 个答案:

没有答案