1

我正在 Cloud 9 IDE 中开发。

这是我收到的错误:

警告:引发错误:错误:听 EACCES

我正在使用 Cloud 9 指定在我的代码中用于监听的端口:process.env.PORT

这是我的代码:

//app.js Socket IO Test
var express = require("express"),
redis = require('socket.io/node_modules/redis'),
io = require('socket.io').listen(app);

var app = express();

var redisPort = [CENSORED]
  , hostname = [CENSORED]
  , password = [CENSORED]
  , db = 1;

var pub = redis.createClient(redisPort, hostname);
var sub = redis.createClient(redisPort, hostname);
var store = redis.createClient(redisPort, hostname);
pub.auth(password, function(){console.log("adentro! pub")});
sub.auth(password, function(){console.log("adentro! sub")});
store.auth(password, function(){console.log("adentro! store")});

io.configure( function(){
io.enable('browser client minification'); // send minified client
io.enable('browser client etag'); // apply etag caching logic based on version number
io.enable('browser client gzip'); // gzip the file
io.set('log level', 1); // reduce logging
io.set('transports', [ // enable all transports (optional if you want flashsocket)
'websocket'
, 'flashsocket'
, 'htmlfile'
, 'xhr-polling'
, 'jsonp-polling'
]);
var RedisStore = require('socket.io/lib/stores/redis');
io.set('store', new RedisStore({redisPub:pub, redisSub:sub, redisClient:store}));
});

app.listen(process.env.PORT);

app.get('/', function (req, res) {
res.sendfile(__dirname + '/index.html');
});

var buffer = [];
io.sockets.on('connection', function(client){
var Room = "";
client.on("setNickAndRoom", function(nick, fn){
fn({msg : "Hello " + nick.nick});
client.join(nick.room);
Room = nick.room;
client.broadcast.to(Room).json.send({ msg: "Se conecto al room: " + nick.room, nick : nick });
});

client.on('message', function(message, fn){
var msg = message; //{ message: [client.sessionId, message] };
buffer.push(msg);
if (buffer.length > 15)
buffer.shift();
client.broadcast.to(Room).json.send(msg);
fn(msg);
});

client.on('disconnect', function(){
client.broadcast.to(Room).json.send({ msg: "Se desconecto"});
});
});

我不确定为什么在使用 Cloud 9 建议的端口时会出现此错误。

提前致谢!

4

1 回答 1

3

难道你不想在让套接字监听它之前创建 app = express() 吗?

于 2013-03-15T12:46:44.540 回答