javascript - socket.io doesn't seem to be starting and doesn't recognize io.configure method -


i trying socket.io running node/express (i have done countless times - pretty baffled). when try configure socket.io io.configure method error:

io.configure(function() {    ^ typeerror: object #<server> has no method 'configure'     @ object.<anonymous> (/home/yz/webdev/ground/app.js:377:4)     @ module._compile (module.js:456:26)     @ object.module._extensions..js (module.js:474:10)     @ module.load (module.js:356:32)     @ function.module._load (module.js:312:12)     @ function.module.runmain (module.js:497:10)     @ startup (node.js:119:16)     @ node.js:902:3 

my code how says on socket.io - i'll post in case:

var express = require('express'); var app = express(); var server = require('http').createserver(app); var io = require('socket.io').listen(server);  server.listen(8000);  //other declarations app.use(... passport.use(...  //some routes app.get(... app.post(...  io.configure(function() {   io.set('transports', ['websocket','xhr-polling','flashsocket']);   io.set('flash policy port', 10843); });  io.sockets.on('connection', function (socket) {    socket.on('message', function (data) {     ...   }); }); 

the error gets thrown @ io.configure method - have done before other sites, don't understand whey isn't working now. thanks.

update

i reading here io.configure doesn't exist anymore - however, can't seem working new way either. here new code:

var express = require('express'); var app = express(); var server = require('http').createserver(app); //var io = require('socket.io').listen(server); var socket = require('socket.io')({   'transports': ['websocket','xhr-polling','flashsocket'],   'flash policy port': 10843 });  var io = socket.listen(server);  io.sockets.on('connection', function (socket) {    socket.on('message', function (data) {      ...   }); }); 

i'm not getting errors, socket.io doesn't seem starting.

you're assigning io server, causing problems when attempt call functions on io available socket.io. try replacing line:

var io = require('socket.io').listen(server); 

with line:

var io = require('socket.io')(server); 

the socket.io docs list couple of configuration patterns can take advantage of, , possible create server using socket.io. since you're creating server, shouldn't need socket.io.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -