Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/**
* 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
You can’t perform that action at this time.