Sailsjs Socket IO
Ich bin neu bei SailsJs und Socket IO. Ich möchte das folgende Socket IO-Beispiel in Sailsjs ausführen. Auf der Serverseite muss ich den folgenden Code ausführen. Aber ich weiß nicht, wo ich diesen Code platzieren soll.
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.