Created
March 24, 2015 14:28
-
-
Save jnwelzel/ffcec172ce2d4d35a550 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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