Skip to content

Instantly share code, notes, and snippets.

@tcr
Created October 23, 2011 07:34
Show Gist options
  • Save tcr/1307000 to your computer and use it in GitHub Desktop.
Save tcr/1307000 to your computer and use it in GitHub Desktop.
Using node.js and socket.io, when I broadcast to all other sockets with a callback, can I get a reference to each socket inside the callback?
# Iterate through all sockets excluding origin
broadcast = (origin, fn) ->
fn(socket) for socket in io.sockets.clients() when socket != origin

No. Best roll your own implementation here. The easiest choice is to use io.sockets.clients() to get a list of all sockets, then exclude the originating socket.

["socket.io","node.js","broadcast","networking"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment