node.js - Socket.io 'on' is returning undefined -


ok, i'm trying learn socket.io , error:

io.socket.on('connection', function (socket) typeerror: cannot call method 'on' of undefined

heres code:

var express = require('express')   , app = express.createserver()   , routes = require('./routes')   , user = require('./routes/user')   , path = require('path')   , io = require('socket.io').listen(app);   // environments app.set('views', __dirname + '/views'); app.set('view engine', 'jade'); app.use(express.favicon()); app.use(express.logger('dev')); app.use(express.bodyparser()); app.use(express.methodoverride()); app.use(app.router); app.use(express.static(path.join(__dirname, 'public')));  app.listen(3000);  app.get('/', routes.index); app.get('/users', user.list);  io.socket.on('connection', function (socket) {     socket.emit('news', { hello: 'world' });     socket.on('my other event', function (data) {         console.log(data);     }); }); 

i know going rather obvious.

should io.sockets.on ("sockets" instead of "socket"):

io.sockets.on('connection', function (socket) {     socket.emit('news', { hello: 'world' });     socket.on('my other event', function (data) {         console.log(data);     }); }); 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -