[英]Express.js close response
Is there a way to close a response? 有没有办法结束回复? I can use res.end()
but it doesn't actually close the socket. 我可以使用res.end()
但它实际上并没有关闭套接字。
What I want to achieve: I am writing a Java program which interfaces with the network, and I am writing a node.js server for this. 我想要实现的目标:我正在编写一个与网络接口的Java程序,我正在为此编写一个node.js服务器。 Java code: Java代码:
String line;
while((line = in.readLine()) != null) {
System.out.println("RES: "+line);
}
But this just keeps hanging.. No end connection, still waiting for input from the socket. 但这只是一直挂着..没有结束连接,仍在等待来自套接字的输入。
Node: 节点:
exports.getAll = function (req, res) {
res.set("Content-Type", "text/plain");
res.set(200);
res.send(..data..);
res.end();
}
however res.end()
does not close the connection.. As said before, java keeps thinking there will be something next so it is stuck in the while loop. 但是res.end()
不会关闭连接。如前所述,java一直认为下一步会有一些东西,所以它会停留在while循环中。
Thank you 谢谢
通过设置HTTP标头来关闭连接而不是默认保持活动策略来解决此问题。
res.set("Connection", "close");
如果真正想要关闭连接的人发现这一点,你可以使用res.socket或res.connection来获取destroy方法附带的net.Socket对象:
res.connection.destroy();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.