I'm working on the long-poll application which uses node.js as a server. The particular task is to immediately learn then the user goes offline. So, I have to listen for the request.close event, right?
I copied following piece of code from the How to check if connection was aborted in node.js server
var http = require("http"),
util = require("util");
var httpServer = http.createServer(function(req, res) {
util.log("new request...");
// notify me when client connection is lost
req.on("close", function(err) {
util.log("request closed...");
});
// wait with response for 15 seconds
setTimeout(function() {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write("response");
res.end();
util.log("response sent...");
}, 15000);
});
httpServer.listen(8888, "127.0.0.1");
util.log("Running on 8888");
I can't make it working properly:
I open in the browser specific URL connected with the node.js server
Immediately after that click the "Stop" button.
Node.js waits for 15 seconds as if the connection was still alive, and then logs "response sent".
I turned off nginx to prevent any problems, the result is the same. I tried to listen the req.connection.on("close") event also, the result is the same again. The nodejs version is 0.4.12.
What could be wrong?