Created
May 31, 2016 13:37
-
-
Save zippy1978/eaa8f1e300cb8138f87ccd7cd2e1b198 to your computer and use it in GitHub Desktop.
Sails.js websocket connection with socket.io-client
This file contains hidden or 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 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