开发者

How to handle NetworkStream.Write failure

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜