gpt4 book ai didi

node.js - 基于 heroku socket.io 服务器的 heroku 空闲连接超时

转载 作者:搜寻专家 更新时间:2023-10-31 23:54:52 28 4
gpt4 key购买 nike

有时我的套接字服务器会出现以下问题:

这里是 heroku 日志:

heroku[router]: at=error code=H15 desc="Idle connection" method=GET path=/socket.io/1/websocket/RcjG0Zjot1U3uwLWX9SI 
host=www.*********.** request_id=69f5aa39-255b-4871-a928-1548ef2fdd4f
fwd="217.200.201.210" dyno=web.1 connect=0 service=306473 status=503 bytes=870

我正在使用 socket.io 库版本 0.9.x 和 Node 0.8.x。它托管在 heroku 上,并激活了 websocket (heroku labs:enable websockets -a myapp)。我没有使用 xhr-polling

这是我实现套接字服务器的方式:

var httpServer = http.createServer(function(request, response) {
var pathname = url.parse(request.url).pathname;
if(pathname == "/") pathname = "index.html";
if(pathname.indexOf("/chat/") != -1 ) pathname = "index.html";
var filename = path.join(process.cwd(), 'public', pathname);
path.exists(filename, function(exists) {
if(!exists) {
response.writeHead(404, { "Content-Type": "text/plain" });
response.write("404 Not Found");
response.end();
return;
}
response.writeHead(200, { 'Content-Type': mime.lookup(filename) });
fs.createReadStream(filename, {
'flags': 'r',
'encoding': 'binary',
'mode': 0666,
'bufferSize': 4 * 1024
}).addListener("data", function(chunk) {
response.write(chunk, 'binary');
}).addListener("close", function() {
response.end();
});
});
});


socket_calls = new socket_calls(webSocket, io, connectedUsers,clients );
webSocket.sockets.on('connection',socket_calls.socket_callback_func );
httpServer.listen(process.env.PORT || 8080, "0.0.0.0");

这个问题似乎只出现在 3g 连接上,一些系统上无法连接到服务器的客户端报告了这个问题。

我尝试使用“网络链接调节器”模拟不良连接,在多个具有 3g 连接和 Wi-Fi 连接的设备上重现该问题,但我无法重现该错误。

最佳答案

我已经解决了。该问题仅出现在与 TIM 业务的 3g 连接上。

我已经从 heroku 命令行工具中禁用了 websocket 支持,并且我已经在 socket.io 上启用了 xhr-polling。

关于node.js - 基于 heroku socket.io 服务器的 heroku 空闲连接超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23713894/

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