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.
1 Answer
req.on("close", function() {
// request closed unexpectedly
});
req.on("end", function() {
// request ended normally
});
6 Comments
Alfred
nice this is new for me also :)
Somebody
Note: 'close' can fire after 'end', but not vice versa. I'm confused. How can close be emitter after end? I can only imagine it vice versa. User dropped connection, but for example request to mysql already sent.
Phaneendra Charyulu Kanduri
both not happening when we switch off wifi. client showing disconnected, but server still connected giving
unavailable-id in peerjs serverSai
@PhaneendraCharyuluKanduri i'm in the same boat now, close triggers if the browser or the tab is closed but if there is an unexpected interruption then it is not triggered. wondering is there any handler that we can leverage.
Naveen
On node 12
close event is fired in the end anyways |
res.connection.destroyed