Socket connection is automatically closed on hero using nodejs

I am working on an IoT project. With nodejs on heroku I created a server on heroku. Then my IoT device will try to establish a connection. But when I tried it, the connection is closed automatically. Below I am using script. It works locally.

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");

      

Please, help.

+3


source to share


1 answer


I am also facing the same problem, but I think the problem might be this

According to this article



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

Likewise, if no data is received from the client within 55 seconds of the window, the connection is terminated and an H28 error is logged.

0


source







All Articles