c# - Catch the exception thrown at client side when the server closed the pipe -
i checked similar questions question seems simpler , straightforward: there server , client , named pipe between.
the client listens messages server sends (while loop).
how detect server closed pipe, softly close client well?
i saw 3 options:
- put
pipehhandle.isclosed
inwhile
condition of listening client loop - catch
objectdisposedexception
hoping catch end of communication , not other failures (this exception not give exceptionerrorcode
). - catch
system.componentmodel.win32exception
, check inside exceptionerrorcode
(-2147467259). standard put "if" in catch code?
i did not find specific exception "ended pipe" although program (without catch) throw exception number 109 or -2147467259, confused.
thanks help.
the common way know other side dead "echo": once in while(let's every 10 seconds) client sends "echo" - meaning simple request server replay. if 3 echo in row(could more, depend on you) did not answered server, client decide server down , disconnect side
Comments
Post a Comment