gpt4 book ai didi

node.js - 使用nodejs在heroku上自动关闭套接字连接

转载 作者:搜寻专家 更新时间:2023-11-01 00:05:24 24 4
gpt4 key购买 nike

我正在从事一个物联网项目。在 heroku 上使用 nodejs,我在 heroku 上创建了一个服务器。然后我的物联网设备将尝试建立连接。但是当我尝试它时,连接会自动关闭。下面是我正在使用的脚本。它在本地工作。

net = require('net');
var clients = [];
net.createServer(function (socket) {
socket.name = socket.remoteAddress + ":" + socket.remotePort
clients.push(socket);
broadcast(socket.name + " joined the chat\n", socket);
socket.on('data', function (data) {
broadcast(socket.name + "> " + data, socket);
});
socket.on('end', function () {
clients.splice(clients.indexOf(socket), 1);
broadcast(socket.name + " left the chat.\n");
});
function broadcast(message, sender) {
clients.forEach(function (client) {
if (client === sender) return;
client.write(message);
});
process.stdout.write(message)
}
}).listen(process.env.PORT || 8899);
console.log("Chat server running at port 8899\n");

请帮忙。

最佳答案

我也面临同样的问题,但我认为问题可能是 this

根据这篇文章

If no data is received from the dyno within the 55 second window the connection is terminated and an H15 error is logged.

Similarly, if no data is received from the client within the 55 second window the connection is terminated an an H28 error is logged.

关于node.js - 使用nodejs在heroku上自动关闭套接字连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44237630/

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