I have two applications a server and a client. I can send messages between the two as long as they are both running.
When I close the server and try to send a message with NetworkStream.Write i get an exception.
What would be the best way to handle this and notify the client th开发者_StackOverflowat the server is down?
Ping is a bad idea. The connection can go down between the ping and the actual message too.
As you yourself pointed out:
wrap the write in a try/catch and display a nice little message to the user.
You could ping the server prior to sending the message, if the ping fails then inform the user and don't send the message etc.
精彩评论