Sending data throgh NamedPipe when server is down
I was wondering how to handle a situati开发者_StackOverflow中文版on where you successfully connected two processes through named pipe (one server and one client), and suddenly (for some reason) the server process ends.
What happens to the pipe? Does it close? What happens to information being sent by the client to the server? Does it get lost? How can the client know if the server is down?
All The Best,
Gil
If you are using System.IO.Pipes
and NamedPipeServerStream
for example, you would get IOException when a pipe is broken or disconnected.
When you are using NamedPipeClientStream
for reading in information from server, I believe the client would wait till a connection is established on the NamedPipeClientStream.Connect()
call alternative you could use NamedPipeClientStream.Connect(Int32)
option to timeout a connection after a predetermined period. Apart from that the StreamReader.ReadLine()
is also capable of throwing IOException
when something does not go well.
The NamedPipeClientStream.IsConnected
would be a simple way to determine if the client is connected successfully to the server or if it is disconnected, closed, or broken.
精彩评论