Safely cleaning up server when Socket is disconnected
-
I'm building a server based around Asynchronous sockets. Clients connect and are asked to authenticate, messages are exchanged using XML. As soon as the client has been authenticated the socket is associated with an object representing the person. The server is working fine except when clients disconnect. If the client disconnects without sending a message to the server (i.e. the connection just drops) then the Socket seems to be closed before some of the server's clean up code can be called -- an ObjectDisposedException is thrown. I need a reference to the Socket since the clean up uses various parts of the type to correctly clean up. Is there any way to ensure that my clean up code is performed before the Socket is disposed? The Dispose method is intended to be used for releasing resources, which isn't strictly the case and it would also require the derived Socket type to essentially be aware of where it's being used. All suggestions are very much appreciated, Paul -- Paul "Put the key of despair into the lock of apathy. Turn the knob of mediocrity slowly and open the gates of despondency - welcome to a day in the average office." - David Brent, from "The Office" MS Messenger: paul@oobaloo.co.uk Download my PGP public key