Created
July 17, 2014 17:28
-
-
Save toddtreece/ee47c17cee30c90a3963 to your computer and use it in GitHub Desktop.
socket.io client example for data.sparkfun.com
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
$ node -v | |
v0.10.29 | |
$ npm install socket.io-client | |
$ node socket.js |
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
var Client = require('socket.io-client'), | |
public_key = 'dZ4EVmE8yGCRGx5XRX1W'; | |
var socket = Client('http://54.88.72.77'); // IP of one of the data.sparkfun.com webservers | |
socket.on('connect_error', console.log); | |
socket.on('connect', function() { | |
console.log('connected'); | |
socket.emit('room', public_key); | |
}); | |
socket.on('disconnect', function() { | |
console.log('disconnected'); | |
}); | |
socket.on('data', function(data) { | |
console.log(data); | |
}); | |
socket.on('clear', function() { | |
console.log('stream cleared'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment