Linked from: http://sailsjs.org/documentation/reference/web-sockets/sails-sockets/broadcast
In an action, service, or arbitrary script on the server:
sails.sockets.broadcast('artsAndEntertainment', { greeting: 'Hola!' });
On the client:
io.socket.on('message', function (data){
console.log(data.greeting);
});
In an action, service, or arbitrary script on the server:
sails.sockets.broadcast(['artsAndEntertainment', 'currentEvents'], { greeting: 'Hola!' });
Client-side usage is exactly the same regardless which rooms are specified:
io.socket.on('message', function (data){
console.log(data.greeting);
});
Remember that the event name is purely for identifying this message on the client; whereas room names are not visible on the client at all, and instead control which client sockets receive the message.
In an action, service, or arbitrary script on the server:
sails.sockets.broadcast('artsAndEntertainment', 'foo', { greeting: 'Hola!' });
On the client:
io.socket.on('foo', function (data){
console.log(data.greeting);
});
If req
is passed in as the last argument, the requesting socket will not receive the broadcasted message:
if (req.isSocket) {
sails.sockets.broadcast('artsAndEntertainment', {
greeting: 'Hola!'
}, req);
}
Hey Iam using Orientdb database server. how to send message to specific id