C# – Only one client can connect to named pipe

asp.net-3.5cnamed-pipes

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!

Best Answer

you can look up some of the info here: Number of Clients that can connect to a Named Pipe

and here in MSDN: http://msdn.microsoft.com/en-us/library/aa365594%28VS.85%29.aspx

from what i understand, you should create a multi-threaded application. main thread should be responsible for the future connections, and each new connection should be launched in new thread.