node.js - Express Route & Socket io -


OK, so my socket IO connection was to send information to the frontal and the client was also able to respond, due to return Savings data

However this does not mean that when this experiment is only on '/ user / home' then socket IO is started in the server.js file. route.

So my question is how do I use socket IO in a path if http server is server.js server < / Div>

In this way I have configured it:

I have an IO. JS library which handles socket io accessories:

  var io = require ('socket.io') (); var redis = require ("redis"); var client = redis.createClient (); io.path ('/ socket'); client.on ('connect', function () {console.log ("Redis successfully connect");}); Io.on ('connection', function (socket) {console.log ('user connected:' + socket.handshake.query.uid_sp); console.log ('socket id:' + socket.id); // Clients.uid_sp = socket.id; //console.log ('a user added:'); client.set (socket.handshake.query.uid_bsp, socket.id);}); Io.notifytransfer = function (uid_bsp, data) {client.get (uid_bsp, function (mistake, socketed) {console.log ('notice:' + socketed); io.to (socket) .emit ('update', data );}); }; Module.exports = Io;   

And I have this library in server.js, and is connected to the server:

  var httpserver = http.createServer (app); var io = requirement ('. / src / utils / io.js'); ... var server = httpserver.listen (app.get ('port'), function () {console.log ('listening server port' + app.get ('port'));}; Io.attach (server);   

Then in my routes (like the rest of the rest of the JS files, front, ....), I can use the notification method, just need the Iio library.

Hope it helps

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -