Sailsjs Socket IO
Jestem nowy w SailsJs i Socket IO. Chcę wykonać poniższy przykład Socket IO w Sailsjs. Po stronie serwera muszę wykonać następujący kod. Ale nie wiem, gdzie umieścić ten kod.
var io = require('socket.io').listen(80);io.sockets.on('connection', function (socket) { socket.emit('news', { hello: 'world' }); socket.on('my other event', function (data) { console.log(data); }); });
I am aware that I can place this inside the Cntroller's function but it will add listener to every request which I dont want.Client Side:
var socket = io.connect('http://localhost'); socket.on('news', function (data) { console.log(data); socket.emit('my other event', { my: 'data' }); });Show me where to place the server side code in sailsjs and help me to execute the above socketIO example.