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 So my question is how do I use socket IO in a path if http server is In this way I have configured it: I have an IO. JS library which handles socket io accessories: And I have this library in server.js, and is connected to the 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 '/ user / home' then socket IO is started in the
server.js file. route.
server.js server < / Div>
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;
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);
Comments
Post a Comment