Get a room.
// in your socket.io code
sio.on('connection', function (socket) {
socket.join('vroom');
});
// ...elsewhere, in your app
app.get('/', function (req, res) {
io.sockets.in('vroom').emit('accelerate', { text: 'Go faster!'});
});
That's it.
I'll be releasing a module later today which provides an even easier,
more expressive way of doing this for large scale deployments of
Socket.io.
Daniel Shaw
@dshaw
io.sockets.socket(< session id>).send('my message') io.sockets.socket(< session id>).emit('event name'[, arguments])
Daniel Shaw
@dshaw
var socket = new io.connect('http://domain.com');
// Server side javascriptsocket.on('connection received', function(data) {myGlobalAppNameSpace.socket = data;});// send myGlobalAppNameSpace.socket.id as a hidden variable on ajax form submit.
io.sockets.on('connection', function(socket) {console.log('socket_id: ' + socket.id + ' has connected');socket.emit('connection received', {timestamp: Date.now(),socket_id: socket.id});});