socket.io配置

发布于 2024-12-09 03:34:24 字数 1280 浏览 0 评论 0原文

我正在尝试按照 https:// 设置 socket.io 的配置github.com/LearnBoost/socket.io/wiki/Configuring-Socket.IO

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

但我收到 TypeError: Object # has no method 'set' ...出了什么问题?我有 io = require("socket.io")

也尝试过,

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

但没有运气。怎么了 ?

编辑:

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);
:::::::::::::::::
app.listen(9999);

这工作正常..但是如果我将其更改为 io = require("socket.io").listen(8080) 它会给我错误,listen 方法不会成立。

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);
:::::::::::::::::
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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

枉心 2024-12-16 03:34:24

require('socket.io') 返回一个 Socket 对象。设置的属性位于 socket.io-manager 上。管理器由 require('socket.io').listen(server) 调用返回。

请注意,您应该将 Web 服务器传递给 socket.io,而不仅仅是端口:

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

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
横笛休吹塞上声 2024-12-16 03:34:24

您需要 var io = require('socket.io').listen(80); 而不仅仅是 require。

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

夏尔 2024-12-16 03:34:24
var io = require('socket.io').listen(80);

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

});

这里有一件重要的事情需要注意。如果您收到错误*process.nextTick 错误,或第一个刻度上的“错误”事件...*,这意味着您有另一个网络服务器(例如 Apache)正在侦听端口 80。

因此,如果您将端口更改为,例如 8080,它应该可以工作:

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

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

});

希望这会有所帮助。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文