我正在尝试在我的Debian linux服务器上运行一个websocket服务器。我按照了大量的教程,但现在我遇到了错误:
我正在关注本教程http://codehenge.net/blog/2011/05/getting-started-with-node-js-and-socket-io-part-2/在尝试显示(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.");
});
});
答案 0 :(得分:1)
更新:我发现了问题!我正在使用不稳定版本的节点。我只是重新使用稳定的,现在每个都很好!