Skip to content

Instantly share code, notes, and snippets.

@simi
Created May 5, 2015 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simi/2fdb7eb9dac59038edb7 to your computer and use it in GitHub Desktop.
Save simi/2fdb7eb9dac59038edb7 to your computer and use it in GitHub Desktop.
chember simple WS broadcaster
var WebSocketServer = require('ws').Server;
var socket = new WebSocketServer({port: 8080});
socket.on('connection', function(connection) {
connection.on('message', function(message) {
console.log(message);
socket.broadcast(message);
});
});
socket.broadcast = function(data) {
this.clients.forEach(function(client) {
client.send(data);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment