Skip to content

Instantly share code, notes, and snippets.

@jnwelzel
Created March 24, 2015 14:28
Show Gist options
  • Save jnwelzel/ffcec172ce2d4d35a550 to your computer and use it in GitHub Desktop.
Save jnwelzel/ffcec172ce2d4d35a550 to your computer and use it in GitHub Desktop.
/**
* Using https://github.com/websockets/ws
*/
var WebSocketServer = require('ws').Server,
wss = new WebSocketServer({port: 8080});
wss.on('connection', function(ws) {
ws.on('message', function(message) {
wss.broadcast(message);
});
ws.send('something');
});
wss.broadcast = function broadcast(data) {
wss.clients.forEach(function each(client) {
client.send(data);
});
};
console.log('Server is ready and listening...');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment