Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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