Filipe Deschamps
unread,Apr 21, 2012, 4:47:49 PM4/21/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to nowjs
Hi guys!
I set a setInterval() in the root of the server.js code to send some
automatic test messages and I expected nowjs to only send 1 message
for everyone with the specified interval. But the end result is, for
every connection, it creates a new setInterval and sends duplicated,
triplicated, etc. messages/broadcasts. The code is really simple, can
you identify what I'm missing?
http = require("http");
nowjs = require("now");
http_server = http.createServer(function(req,res){
html = require("fs").readFileSync(__dirname + "/index.html");
res.end(html);
});
http_server.listen(8080);
var everyone = nowjs.initialize(http_server);
everyone.now.broadcastMessage = function(message){
everyone.now.receiveMessage(message);
};
setInterval(everyone.now.broadcastMessage,2000,"Test message");
-----
So, if I have one browser opened, the server broadcast 1 message for
every 2 seconds. If I have two browsers opened, it broadcasts 2
messages for every 2 seconds. 3 browsers, 3 messages every 2 seconds,
etc.