I am currently learning about named pipes in Windows using ASP.NET 3.5 and C#.
I wrote a small server program which creates a named pipe:
using (NamedPipeServerStream pipeStream = new NamedPipeServerStream(pipeName))
{
pipeStream.WaitForConnection();
// do sth.
}
and a client application opening the pipe like this:
using (NamedPipeClientStream pipeStream = new NamedPipeClientStream(pipeName))
{
pipeStream.Connect();
// do sth.
}
This works great as long as only one client connects to the pipe. It can both read and write. If I try to connect a second client, the code never exceeds the line
pipeStream.Connect();
Both the server and all clients are running on the same machine.
Any ideas?
Thank you very much in advance!
Thanks for the fast help.
I already handled the real processing in separate threads but forgot to mention that.
A co-worker found the problem though:
I had a StreamReader enclosed by another using block in the posted NamedPipeServerStream-using block on the server side.
When this block finished closing the StreamReader, it also disconnected the NamedPipeServerStream for some reason. Also I wasn’t enclosing the pipeStream.WaitForConnection() in a loop.