Only one client can connect to a named pipe

I am currently studying named pipes in Windows using ASP.NET 3.5 and C #. I wrote a small server program that creates a named pipe:

using (NamedPipeServerStream pipeStream = new NamedPipeServerStream(pipeName)) { pipeStream.WaitForConnection(); // do sth. } 

and a client application opening this channel as follows:

 using (NamedPipeClientStream pipeStream = new NamedPipeClientStream(pipeName)) { pipeStream.Connect(); // do sth. } 

This works great if only one client connects to the pipe. He can read and write. If I try to connect a second client, the code will never exceed the line

 pipeStream.Connect(); 

Both servers and all clients work on one computer. Any ideas?

Thank you in advance!

+6
c # named-pipes
source share
4 answers

Thanks for the quick help.

I already handled the actual processing in separate threads, but forgot to mention it. The employee found the problem though:

I had a StreamReader enclosed by another block using a block in a hosted NamedPipeServerStream block on the server side.

When this block completed closing StreamReader, for some reason, it also disabled NamedPipeServerStream. Also, I did not include pipeStream.WaitForConnection () in the loop.

+1
source share

you can find the information here: The number of clients that can connect to the named pipe

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

from what I understand, you have to create a multithreaded application. the main thread should be responsible for future connections, and each new connection should start in a new thread.

+4
source share

The real channel (the one in the hardwre store) has two ends. Therefore, I expect the named pipe to have exactly two endpoints, one for the server process and one for the client process.

However, whatever final answer I would suggest looking at WCF - it supports network binding (and many others, such as binary TCP, SOAP with or without WS- *, just changing the configuration) and handles server activation and multithreading for you .. net 3.5 is available, so I would choose it.

0
source share

Please see my answer here on how to implement a multi-threaded pipe server in .NET .

0
source share

All Articles