C# named pipes over a network

c

I'm trying to make an app that requires communication over a network. I was following the MSDN doc for named pipes here: http://msdn.microsoft.com/en-us/library/bb546085.aspx

I've tried the code from MSDN but no luck.

I saw that "." has to be replaced with the network name on the client side, which I did. I tried the network name and the server PC name but both failed to connect to the server (my laptop).

Now I'm not sure what to do – any advice? (The code below gets me "The network path was not found")

using System;
using System.IO;
using System.IO.Pipes;

class PipeClient
{
    static void Main(string[] args)
    {
        using (NamedPipeClientStream pipeClient =
            new NamedPipeClientStream("xxx.xxx.x.x", "testpipe", PipeDirection.InOut))
        {

            // Connect to the pipe or wait until the pipe is available.
            Console.Write("Attempting to connect to pipe...");
            pipeClient.Connect();

            Console.WriteLine("Connected to pipe.");
            Console.WriteLine("There are currently {0} pipe server instances open.",
               pipeClient.NumberOfServerInstances);
            using (StreamReader sr = new StreamReader(pipeClient))
            {
                // Display the read text to the console
                string temp;
                while ((temp = sr.ReadLine()) != null)
                {
                    Console.WriteLine("Received from server: {0}", temp);
                }
            }
        }
        Console.Write("Press Enter to continue...");
        Console.ReadLine();
    }
}

Best Answer

When you specify a computer name, even your own computer's name, it uses the standard network protocols/stack/etc.

You probably need to open a firewall port. TCP 445. Also, by default, Windows allows all outgoing communications. You should only need to add an inbound port exception. Your configuration may vary of course. .NET 3.5 (C#) Named pipes over network

Related Topic