Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect diconnected Duplex Polling clients

I have followed Tomek Janczuk's Pub/sub sample using HTTP polling duplex WCF channel but I've noticed that when a client disconnects by closing the browser the service does not notice on the next callback. I would have expected an exception or something to say that the endpoint was not there any longer.

How can you know when a client is gone, so as to stop publishing to that client?

like image 732
Ralph Shillington Avatar asked Nov 10 '10 19:11

Ralph Shillington


2 Answers

To know for sure: impossible.

When a TCP connection is closed (underlying an HTTP call), a special TCP message is sent to the server - FIN packet. Although HTTP is stateless, underlying TCP connection is stateful and with keep alive, underlying TCP connection usually stays open. If client is disposed, TCP connection is closed and normally a message sent to the server. But if it crashes or its network is disconnected, it would not have the time to do this. So in one word, you can never be sure.

Here for more info.

like image 54
Aliostad Avatar answered Oct 01 '22 20:10

Aliostad


It seems there's one unsatisfactory, albeit simple solution: If the client callback times out, don't call it again.

In my system I've also implemented a manual "check" call - every n seconds the server calls a parameterless method over the callback channel for each registered client, just to see if the client is still there. I'm starting to wonder if that really was a good idea - I've got a new problem where a callback timeout keeps occurring because I've suspended the client in the debugger.

like image 38
Andrew Shepherd Avatar answered Oct 01 '22 22:10

Andrew Shepherd