0

I checked similar questions but my question seems simpler and straightforward: There are a server and a client and a named pipe between.

The client listens to the messages the server sends (while loop).

How do I detect that the server closed the pipe, so I softly close the client as well?

I saw 3 options:

  1. Put pipeHhandle.IsClosed in the while condition of the listening client loop
  2. Catch ObjectDisposedException hoping that it will catch only end of communication and not other failures (This exception does not give exception errorCode).
  3. Catch System.ComponentModel.Win32Exception and check inside the exception errorCode (-2147467259). Is it standard to put an "if" in catch code?

I did not find any specific exception for "ended pipe" although the program (without catch) does throw an exception whose number is 109 or -2147467259, I am confused.

Thanks for any help.

No Idea For Name
  • 11,411
  • 10
  • 42
  • 70
Joshua
  • 151
  • 1
  • 1
  • 9

1 Answers1

0

the most common way to know that the other side is dead is the "echo": once in a while(let's say every 10 seconds) the client sends an "echo" - meaning a simple request to the server to get replay. if 3 echo in a row(could be more, depend on you) did not answered by the server, the client decide that the server is down and disconnect his side

No Idea For Name
  • 11,411
  • 10
  • 42
  • 70