javascript - Socket.io inside express routes -
is possible use socket.io inside express route?
i want this:
server
app.js:
app.get('/cool_page/',users.cool_page);
users.cool_page:
if (5>3){ socket.emit('first_connection',"true statement"); }
client:
socket.on('first_connection',function(data){ if (data === "true statement"){ console.log("success"); }
so far hadn't been working. tried envelope users.cool_page in io.sockets.on("conection",function(socket){code...}), didn't work. redefined variables inside users.cool_page; like
var express = require('express'); var app = express(); var server = require('http').createserver(app); var io = require('socket.io').listen(server);
but still doesn't work: without outputting error.
i appreciate help. thanks.
the short answer yes need make sure bind socket calls request using middleware or request emulator. better answer here leverage framework such expressio implement in more robust fashion.
Comments
Post a Comment