C# – How to use named pipes over network

cmsdnnamed-pipesnetpipe

I'm trying to create a connection over network via named pipes. I'm doing it as it says in msdn. I create pipes server side with function.

CreateNamedPipe(
                     "\\\\.\\pipe\\myNamedPipe",
                     DUPLEX | FILE_FLAG_OVERLAPPED,
                     0,
                     255,
                     BUFFER_SIZE,
                     BUFFER_SIZE,
                     0,
                     IntPtr.Zero);

and trying to connect via CreateFile() function

CreateFile(
                  "\\\\10.0.0.29\\pipe\\myNamedPipe",
                  GENERIC_READ | GENERIC_WRITE,
                  0,
                  IntPtr.Zero,
                  OPEN_EXISTING,
                  FILE_FLAG_OVERLAPPED,
                  IntPtr.Zero);

10.0.0.29 is server machines ip. If I'm trying to run client side program on server machine with pipe name "\\.\pipe\myNamedPipe" or "\\10.0.0.29\pipe\myNamedPipe" (10.0.0.29 is servers ip) or "\\localhost\pipe\myNamedPipe" it works fine.

So how to use named pipes over network?

Best Answer

Starting with version 3.5, named pipes are supported natively in the .NET Framework, you don't have to use tedious interop p/invoke code. See this introduction article here: .NET 3.5 Adds Named Pipes Support for a sample.

Using this constructor overload, NamedPipeClientStream Constructor (String, String), you can pass a server name argument.