NODEJS problem
Posted: Fri Nov 08, 2013 12:16 pm
Hello
I'm working with nodejs, what I have now is that it adds 1 second = +1.
What I want is if you jiont with a new browser that game will count where the other remained. So the other at 10 then the other also start at 10 and not at 0
My code:
app.js
HTML
I hope if you can help me, I've tried console.log but I do not know how I can give console.log back. (socket.emit('time', (here consolelog);)
Sorry for bad english me, I'm a Dutchman who can english bad.
I'm working with nodejs, what I have now is that it adds 1 second = +1.
What I want is if you jiont with a new browser that game will count where the other remained. So the other at 10 then the other also start at 10 and not at 0
My code:
app.js
Code: Select all
io.sockets.on('connection', function (socket) {
var counter = 0;
socket.on('testconnection', function() {
setInterval(function() {
var time = counter++;
console.log(time);
socket.emit('time', time);
}, 1000 );
});
});
Code: Select all
var socket = io.connect('http://localhost:8080');
socket.emit('testconnection');
socket.on('time', function(data){
document.getElementById("demo").innerHTML= data;
});
Sorry for bad english me, I'm a Dutchman who can english bad.