views:

78

answers:

1

I searched on the web for a solution to my question, but with no results until now.
I did a test with a Silverlight app, a SocketServer and a SocketClient (with is a silverlight app).
In Debug mode, with both apps running, when I close the browser window, I did enjoyed to see that an event is fired on server and the Socket connection is automatically closed.

The big mystery begun. How that really happened ?
What about shutting down the client machine by pressing the power button ?
Will my event still fired or I will end up with a stack overflow on server for to many unclosed Socket connections ?

A: 

On the server, you should really be polling your socket connections to see if they are still alive. Sending out "Are you still alive" messages.

Usually once a socket connection is lost, sending data down the socket will cause it to fall over with an exception.

Unfortunately computers often can't detect if a socket has lost it's link until you try and do something with it. The only time it knows is when the client (or server) sends a "close connection" command (which is often done in .NET via the Socket.Close() method).

Sockets are a pain like that.

Sekhat