socket.io配置
我正在尝试按照 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
require('socket.io')
返回一个 Socket 对象。设置的属性位于 socket.io-manager 上。管理器由require('socket.io').listen(server)
调用返回。请注意,您应该将 Web 服务器传递给 socket.io,而不仅仅是端口:
require('socket.io')
returns a Socket object. The set properties are on socket.io-manager. The manager is returned byrequire('socket.io').listen(server)
call.Note that you should be passing a web server to socket.io, not just a port:
您需要
var io = require('socket.io').listen(80);
而不仅仅是 require。You want
var io = require('socket.io').listen(80);
instead of just require.这里有一件重要的事情需要注意。如果您收到错误*process.nextTick 错误,或第一个刻度上的“错误”事件...*,这意味着您有另一个网络服务器(例如 Apache)正在侦听端口 80。
因此,如果您将端口更改为,例如 8080,它应该可以工作:
希望这会有所帮助。
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:
Hope this helps.