Skip to content

Instantly share code, notes, and snippets.

@mrjazz
Created January 26, 2016 16:03
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 mrjazz/217489fa46787bc72a97 to your computer and use it in GitHub Desktop.
Save mrjazz/217489fa46787bc72a97 to your computer and use it in GitHub Desktop.
// npm install websocket
var server = require('websocket').server, http = require('http');
var socket = new server({
httpServer: http.createServer().listen(8080)
});
socket.on('request', function(request) {
var connection = request.accept(null, request.origin);
connection.sendUTF('hi');
setInterval(function() {
connection.sendUTF(Math.round(Math.random() * 100));
}, 1000);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment