This project has moved. For the latest updates, please go here.

Check Connectivity

Sep 27, 2012 at 7:24 PM

I am not seeing any public properties to check to see if a Client IsConnected to the server and visa-verse. Would this need to be added? It seems like it would be common thing to have in a TCP library. I could be missing it again?

 

if (ClientSocket.IsConnected)
{
     //Communicate with server.
}

If I shut down the server and still have the client send messages, exceptions get thrown.

Coordinator
Sep 27, 2012 at 11:45 PM
Edited Sep 27, 2012 at 11:45 PM

The library does not have an IsConnected property, but this is not an oversight. Socket does expose a Connected property, but this is a mistake in the API design, IMO.

Due to the nature of network communications, you cannot ever know that a connection will be good for the next piece of data; you just have to send data and see if it completes successfully or with an error.

http://nitoprograms.blogspot.com/2009/06/using-socket-as-connected-socket.html

       -Steve