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

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -