I'm trying to use NamedPipeServerStream
to create a named pipe server in .Net 4. I'm using BeginWaitForConnection
to wait for the connection, so that I can abort the wait if the server is to be shut down.
Everything works well for the first client --- the connection is acknowledged, the data received, and the response sent OK. However, after the client disconnects everything breaks. I'm calling BeginWaitForConnection
again to wait for a new connection, but this is throwing an IOException
saying that the "pipe is broken".
How can I wait for a second client on the same pipe?
Create a new instance of NamedPipeServerStream
specifying the same pipe, and call BeginWaitForConnection
on that.
i.e. Don't try to reuse a NamedPipeServerStream
object for different clients: one instance should service one client connection/conversation, then be disposed.
See also Multithreaded NamePipeServer in C#
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With