2

我正在尝试制作一个基于 nodejs 的 IRC Web 客户端(使用https://github.com/martynsmith/node-irc和 socket.io),但我遇到了一些问题。

当我启动服务器并第一次连接到它时,一切正常,客户端收到“注册”事件,之后一切正常。

如果我刷新页面,服务器仍然会收到 init 事件(带有服务器和昵称),但 IRC 客户端没有连接(尝试在 4000 毫秒后重新连接,但每次收到“连接得到‘关闭’事件”消息) .

代码:

客户端:

var socket;
socket = io.connect('http://localhost:8000');
...
socket.emit('init', { nick: $(".popup #nume").val(), channels: channels });

服务器端:

io = require('socket.io').listen(8000);

irc = require('irc');

console.log("Started server..");

io.sockets.on('connection', function(socket) {
        socket.on('init', function(data) {
                console.log('io connection with id ' + socket.id);
                console.log('socket length: ' + sockets.length);

                var first, i, good, new_message;

                sockets.push(socket);

                socket.nickname = data.nick;
                socket.channels = data.channels;
                first = 0;

                console.log('Init from : ' + socket.nickname + ' ' + socket.channels);

                socket.client = new irc.Client('localhost', socket.nickname, {
                        port: 6667,
                        debug: true,
                        showErrors: true,
                        autoRejoin: true,
                        autoConnect: false,
                        channels: socket.channels,
                        secure: false,
                        retryDelay: 4000,
                        retryCount: 1000
                });

                socket.client.connect();

                socket.client.addListener('registered', function(message) {
                        socket.client.list();

                        console.log('Registered to irc');
                });

日志:

io connection with id oFrdaN8WhQAE4mEh62uI
socket length: 1
Init from : test 
8 Jun 04:33:50 - SEND: nickserv :ghost test
8 Jun 04:33:50 - SEND: NICK test
8 Jun 04:33:50 - SEND: USER nodebot 8 * :nodeJS IRC client
Netrror: Error: write EPIPE
8 Jun 04:33:50 - Connection got "close" event
8 Jun 04:33:50 - Disconnected: reconnecting
8 Jun 04:33:50 - Waiting 4000ms before retrying

所以,问题是即使它连接到服务器,它也无法连接到 IRC 服务器(每次它收到“连接得到'关闭'事件”消息)。

4

0 回答 0