Skip to content

Instantly share code, notes, and snippets.

@sighrobot
Created December 11, 2014 20:20
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 sighrobot/f3fae647dec7d8fffc31 to your computer and use it in GitHub Desktop.
Save sighrobot/f3fae647dec7d8fffc31 to your computer and use it in GitHub Desktop.
Node WS
var levels = 'LEVEL DATA';
var ready= false;
var WebSocket = require('ws'),
ws = new WebSocket('ws://hidden-fortress-3752.herokuapp.com');
ws.on('open', function() {
console.log('open function fired!')
ws.send('Arduino here!' );
ready = true;
});
ws.on('error', function(error) {
console.log(error);
});
ws.on('message', function(msg) {
console.log('client received ' + msg);
});
setInterval(function() {
if (ready) {
ws.send(levels, function(error) {console.log(error ) });
console.log('sent: ' + levels);
}
}, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment