2012-04-03 137 views
0

我试图在我的Debian Linux服务器上运行websocket服务器。我遵循教程的分配,但现在我陷入了一个错误:Socket.IO Websocket服务器超出最大调用堆栈大小

我正在关注本教程http://codehenge.net/blog/2011/05/getting-started-with-node-js-and-socket-io-part-2/ Everyting在尝试显示(hello)时正常工作,但是当我尝试包含Socket.IO时出现此错误。

info - socket.io started 

/usr/local/lib/node_modules/socket.io/lib/manager.js:0 
(function (exports, require, module, __filename, __dirname) { /*! 
^ 
RangeError: Maximum call stack size exceeded 

任何想法?

socketio-test.js

var http = require('http') 
, url = require('url') 
, fs = require('fs') 
, server; 

server = http.createServer(function(req, res){ 
// your normal server code 
var path = url.parse(req.url).pathname; 
switch (path){ 
case '/': 
res.writeHead(200, {'Content-Type': 'text/html'}); 
res.write('<h1>Hello! Try the <a href="/socketio-test.html">Socket.io Test</a></h1>'); 
res.end(); 
break; 
case '/socketio-test.html': 
fs.readFile(__dirname + path, function(err, data){ 
if (err) return send404(res); 
res.writeHead(200, {'Content-Type': path == 'json.js' ? 'text/javascript' : 'text/html'}) 
res.write(data, 'utf8'); 
res.end(); 
}); 
break; 

default: send404(res); 
} 
}), 

send404 = function(res){ 
res.writeHead(404); 
res.write('404'); 
res.end(); 
}; 

server.listen(8080); 

// socket.io, I choose you 
var io = require('/usr/local/lib/node_modules/socket.io').listen(server); 

// on a 'connection' event 
io.sockets.on('connection', function(socket){ 

    console.log("Connection " + socket.id + " accepted."); 

    // now that we have our connected 'socket' object, we can 
    // define its event handlers 
    socket.on('message', function(message){ 
     console.log("Received message: " + message + " - from client " + socket.id); 
    }); 

    socket.on('disconnect', function(){ 
    console.log("Connection " + socket.id + " terminated."); 
    }); 

}); 

回答

1

更新:我发现这个问题!我正在使用一个不稳定的节点版本。我只是重新安装使用稳定的,现在一切都很好!

相关问题