Use of Named Pipes in .Net

K

Ken Allen

Is there any built-in facility for handling named pipes in C#/.Net, or must
one use unsafe code to access the WIN32 API directly?

There exists some code that uses named pipes heavily and there exists a need
for that code to send some information to a new .Net service I am writing.
It is a relatively simple matter for the existing code to use a named pipe
to send the data, but I can find no references to how I can create the named
pipe and manage it from the .Net side.

-Ken
 
D

David Browne

Ken Allen said:
Is there any built-in facility for handling named pipes in C#/.Net, or must
one use unsafe code to access the WIN32 API directly?

There exists some code that uses named pipes heavily and there exists a need
for that code to send some information to a new .Net service I am writing.
It is a relatively simple matter for the existing code to use a named pipe
to send the data, but I can find no references to how I can create the named
pipe and manage it from the .Net side.

You must use Win32 to create or open the named pipe, but once you have a
handle to the named pipe, you can just wrap it in a System.IO.FileStream to
read and write.

To replicate the example here
http://msdn.microsoft.com/library/d.../en-us/ipc/base/multithreaded_pipe_server.asp

for a mutithreaded pipe server, it looks like you'll need to call

CreateNamedPipe
ConnectNamedPipe
DisconnectNamedPipe
CloseHandle

through P/Invoke.

The FileStream will take care of ReadFile, WriteFile, FlushFileBuffers and
CloseHandle on the connected pipe instance.

David
 
K

Ken Allen

Unfortunate. I did read the other response concerning using the CreateFile()
API call first, but...

Am I correct in my believe that a simple TCP/IP socket should be no problem
for this type of solution? The existing C++ (not .Net) service could send
the data buffer over the TCP/IP socket and the .Net service could create and
receive over the socket?

-Ken
 
U

UAError

Ken Allen said:
Is there any built-in facility for handling named pipes in C#/.Net, or must
one use unsafe code to access the WIN32 API directly?

There exists some code that uses named pipes heavily and there exists a need
for that code to send some information to a new .Net service I am writing.
It is a relatively simple matter for the existing code to use a named pipe
to send the data, but I can find no references to how I can create the named
pipe and manage it from the .Net side.

-Ken

Item 13.13 Using Named Pipes to Communicate
http://cookbooks.oreilly.com/

Source Code is here
http://examples.oreilly.com/csharpckbk/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top