res.end()在超时指定之前关闭连接

时间:2018-12-13 20:09:11

标签: node.js server connection

我正在竭尽全力在res.end()之后保持打开状态,但没有成功。

代码如下:

app.post("/enddev", (req, res) => {
  console.log("REQUEST TO ", req.route.path);
  console.log("Req Header ", req.headers);
  socket = res.socket;
  socket.setKeepAlive(true, 60 * 1000);
  var count = 0;
  setInterval(() => {
    console.log(++count);
  }, 1000);
  res.write("request\r\n");
  res.end();
});

server.on("connection", socket => {
  console.log(
    "New connection",
    "Address: " + socket.address().address,
    "Port: " + socket.address().port
  );

  socket.setTimeout(60 * 1000);
  socket.on("timeout", () => {
    console.log("socket timeout");
    socket.end();
  });

  socket.on("close", hadError => {
    console.log(
      hadError
        ? "Socket closed due to ERROR during transmission"
        : "Socket closed"
    );
  });
});

我在Google上搜索了一下,发现res.end不应该关闭连接。

这是我尝试后的控制台输出:

enter image description here

0 个答案:

没有答案