Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node.js http server, detect when clients disconnect

Tags:

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.

like image 777
Jeroen Avatar asked Jul 04 '11 14:07

Jeroen


1 Answers

req.on("close", function() {   // request closed unexpectedly });  req.on("end", function() {   // request ended normally }); 
like image 137
Raynos Avatar answered Oct 19 '22 23:10

Raynos