开发者

socket.io configuration

I am trying to set the configuration for socket.io as per https://github.com/LearnBoost/socket.io/wiki/Configuring-Socket.IO

io.set('log level', 1);

But I'm getting TypeError: Object # has no method 'set' ... what's wrong? I have io = require("socket.io")

Also tried,

io.configure('production', function(){
    io.set('log level', 1);
});

but no luck. what's wrong ?

EDIT:

require.paths.push('/cygdrive/c/Personal/software/nodejs/NODE/node_modules');
var express = require("express"),
    fs = require("fs"),
    form = require('connect-form'),
    app = express.createServer(
        form({ keepExtensions: true })
    ),
    sys = require("sys"),
    RentModel = require("./rent_schema"),
    UserModel   = require("./track_schema"),
    io = require("socket.io"),
    fb = require('facebook-js'),
    Twitter = require('./Twitter_Analysis'),
    Foursquare = require('./Foursquare_Analysis'),
    YQL = require("yql"),
    settings = require("./settings");



socket = io.listen(app);
::::::::::开发者_如何学Python:::::::
app.listen(9999);

This works fine.. But if I change it to io = require("socket.io").listen(8080) it gives me error, listen method not found.


require('socket.io') returns a Socket object. The set properties are on socket.io-manager. The manager is returned by require('socket.io').listen(server) call.

Note that you should be passing a web server to socket.io, not just a port:

var app = require('http').createServer(handler),
    io  = require('socket.io').listen(app);

io.set('log level', 2);

app.listen(8080); // this is the server, not socket.io


You want var io = require('socket.io').listen(80); instead of just require.


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

io.configure( function(){
    io.set('log level', 3);

});

There is one important thing to note here. If you get the error*process.nextTick error, or 'error' event on first tick...* that means that you have another webserver, like Apache, listening to port 80.

So, if you chnage the port to, for example 8080, it should work:

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

io.configure( function(){
    io.set('log level', 3);

});

Hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜