gpt4 book ai didi

linux - Socket.IO Websocket 服务器超出最大调用堆栈大小

转载 作者:太空宇宙 更新时间:2023-11-04 11:33:00 25 4
gpt4 key购买 nike

我正在尝试让 websocket 服务器在我的 Debian Linux 服务器上运行。我遵循了很多教程,但现在我遇到了一个错误:

我正在学习本教程 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

有什么想法吗?

套接字测试.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.");
});

});

最佳答案

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

关于linux - Socket.IO Websocket 服务器超出最大调用堆栈大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9985446/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com