I have two applications communicating through a socket. In the receiving application I use the NetworkStream class to read data from the socket. I call myNetworkStream.BeginRead(buffer, 0, size, new AsyncCallback (MyCallbackMethod), state); MyCallbackMethod is then called when data is coming in, or when the connection is closed by the sender. I then call myNetworkStream.EndRead(), and if the connection is closed I get an exception. Is catching this exception the only way to detect that sender has closed the connection? I tried to use NetworkStream.DataAvailable, but this property is always false when the callback method is called, unless I set a breakpoint or call Thread.Sleep(10), then I guess some other thread sets it to true if the connection is open. So DataAvailable does not work... I guess I am looking for some OnConnectionClosedEvent, or some boolean property I could test on...
=================================== This list is hosted by DevelopMentorĀ® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com
