I'm trying to make an nodejs based IRC web client (using https://github.com/martynsmith/node-irc and socket.io), and I have some problems.
When i start the server, and connect to it the first time, everything works ok, the client gets the "registered" event and everything works after that.
If i refresh the page, the server still gets the init event (with the server and nickname), but the IRC client doesn't connect (tries to reconnect after 4000ms but everytime it gets a "Connection got 'close' event" message).
Code:
Client-side:
var socket;
socket = io.connect('http://localhost:8000');
...
socket.emit('init', { nick: $(".popup #nume").val(), channels: channels });
Server-side:
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');
});
Logs:
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
So, the problem is that even if it connects to the server, it is unable to connect to the IRC server (everytime it gets a "Connection got 'close' event" message).