Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Does broadcast to subscribers only?

Does broadcast to subscribers only?


Please examine the server-side code below. Assuming that is abc77 at some instant, will every connected browser receive a socket message 'my_model/abc77:update', or only the ones that have subscribed to this particular message, regardless of whether the event is raised or not?

To clarify, using a practical application: will a hacker be able to receive the message 'my_model/abc77:update' using the browser's developer console, even if his instance of my application has no subscription to it, not knowing that is abc77?

var io = require('');
io.listen ( server ).sockets.on ( 'connection', function ( socket ) {

    socket.on('my_model:update', function(data, callback) {, function(err){
            if (!err) {

Problem courtesy of: Bijou Trouvaille


It's broadcasted to every other socket connected. To restrict the broadcast to a certain group of sockets, use rooms.

Solution courtesy of: Betamos


View additional discussion.

This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Does broadcast to subscribers only?


Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription