I'm using the websocket-plugin i C2, and I'm learning myself to program node.js servers. I am able to connect to the server and send and receive messages. I have made a "game" that counts clicks on a button, but if I open it on my PC and phone, changes only happens on the device where the action is done. Do I have to identify each device or something? And/or is there a way to broadcast it to every client connected? Any help would be appreciated.
Here's my server script so far:
var WebSocketServer = require('ws').Server
, wss = new WebSocketServer({ port: 8080 });
var total = 0;
wss.on('connection', function connection(ws) {
ws.on('message', function incoming(message) {
total += 1;
console.log('received: %s, total=' + total, message);
ws.send(total);
});
});[/code:tocpixrl]