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.