Skip to content

Instantly share code, notes, and snippets.

@zippy1978
Created May 31, 2016 13:37
Show Gist options
  • Select an option

  • Save zippy1978/eaa8f1e300cb8138f87ccd7cd2e1b198 to your computer and use it in GitHub Desktop.

Select an option

Save zippy1978/eaa8f1e300cb8138f87ccd7cd2e1b198 to your computer and use it in GitHub Desktop.
Sails.js websocket connection with socket.io-client
var socket = require('socket.io-client')('http://localhost:1337' + '?__sails_io_sdk_version=0.11.0');
socket.on('connect', function(){
console.log("Socket is connected !");
// Subscribe
socket.emit('post', {url: 'http://localhost:1337/subscribe',data: {key: value}}, function() {
});
});
// Events handling
socket.on('error', function(err){
console.log('Error : ' + err);
});
socket.on('update', function(data){
console.log("Property updated : " + JSON.stringify(data));
});
socket.on('disconnect', function(){
console.log("Socket disconnected !");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment