node.js http server, detect when clients disconnect

I am using express with node.js for a http server. I store the response object so I can stream events down to the client on that channel. Is there a way to detect when the client disconnects? When I kill my client I can still write to the response object without getting any kind of exception/error. It looks like the service keeps the underlying tcp channel open as long as I keep writing to the response object.

Answers


req.on("close", function() {
  // request closed unexpectedly
});

req.on("end", function() {
  // request ended normally
});

Need Your Help

Unable to read data from the transport connection : An existing connection was forcibly closed by the remote host

c# .net ioexception

I have a server app and sometimes, when the client tries to connect, I get the following error: