mercredi 4 février 2015

Real time text using node.js


I have a node.js server that connects to an IRC channel. I can successfully output all messages from the channel to the console, but I'd like the messages to be displayed in real time on a webpage.


I am looking into socket.io but can't come up with anything, is this the best way?


All I need to know is how to update text on the webpage in realtime, I can see the messages if I refresh the page, but it is 1 message at a time.


I believe I need a client script for this, but I am unsure where to start. Thanks!



// Get the lib
var irc = require("irc");

// Create the bot name
bot.addListener("message#", function(nick, to, text, message) {
console.log(nick, " :=> ", text);
});

var http = require('http');
http.createServer(function (req, res) {

var bot = new irc.Client(config.server, config.nick, config);

bot.addListener("message#", function(nick, to, text, message) {
console.log(nick, " :=> ", text);
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write(text);
res.end(text);
});
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');




Aucun commentaire:

Enregistrer un commentaire