我正在竭尽全力在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
不应该关闭连接。
这是我尝试后的控制台输出: