On Monday 5 November 2012 at 14:22, Pablo Villoslada Puigcerber wrote:
You can use it as middleware:var socketHandler = function(req, res, next) {io.sockets.on('connection', function (socket) {socket.emit('news', { hello: 'world' });socket.on('disconnect', function() {console.log('A socket with id ' + socket.id + ' disconnected');});});next(); // Passing the request to the next handler in the stack.}app.get('/', routes.index);app.get('/another', socketHandler, another.index);Cheers, Pablo.
On Friday, September 7, 2012 1:45:48 PM UTC+2, Marshall wrote:hello, i'm a nodejs newbie and i really need you guys' help!currently, i'm using socket.io with expressjs together and all the examples i saw through internet are using socket.io in the app.js where server is created. but what i want to do is just using socket.io in one sub path of root directory.(another js file in routes directory)i thought maybe i can pass the http server object to my route file or call socket.io in middleware but i didn't do them successfully.so can you tell me a simple and straight-forward way to do the thing like that?thank you guys in advance.
Our MVC framework, Sails, was designed for this purpose. It enforces authentication rules and routes Socket.io messages automatically to the appropriate Express route.
hello, i'm a nodejs newbie and i really need you guys' help!currently, i'm using socket.io with expressjs together and all the examples i saw through internet are using socket.io in the app.js where server is created. but what i want to do is just using socket.io in one sub path of root directory.(another js file in routes directory)i thought maybe i can pass the http server object to my route file or call socket.io in middleware but i didn't do them successfully.so can you tell me a simple and straight-forward way to do the thing like that?thank you guys in advance.