NamedPipeServerStream Constructor (String, PipeDirection)

NamedPipeServerStream Constructor (String, PipeDirection)

 

Initializes a new instance of the NamedPipeServerStream class with the specified pipe name and pipe direction.

Namespace:   System.IO.Pipes
Assembly:  System.Core (in System.Core.dll)

public NamedPipeServerStream(
	string pipeName,
	PipeDirection direction
)

Parameters

pipeName
Type: System.String

The name of the pipe.

direction
Type: System.IO.Pipes.PipeDirection

One of the enumeration values that determines the direction of the pipe.

Exception Condition
ArgumentNullException

pipeName is null.

ArgumentException

pipeName is a zero-length string.

ArgumentOutOfRangeException

pipeName is set to "anonymous".

-or-

direction is not a valid PipeDirection value.

NotSupportedException

pipeName contains a colon (":").

PlatformNotSupportedException

The operating system is Windows Millennium Edition, Windows 98, or Windows 95, which are not supported.

IOException

The maximum number of server instances has been exceeded.

This constructor creates a NamedPipeServerStream object that has the following characteristics:

The following example demonstrates a method to send a string from a parent process to a child process using named pipes. This example creates a NamedPipeServerStream object in a parent process. The NamedPipeServerStream object has a PipeDirection value of Out, which then blocks until a NamedPipeClientStream object establishes a connection to the current NamedPipeServerStream object.

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

class PipeServer
{
    static void Main()
    {
        using (NamedPipeServerStream pipeServer =
            new NamedPipeServerStream("testpipe", PipeDirection.Out))
        {
            Console.WriteLine("NamedPipeServerStream object created.");

            // Wait for a client to connect
            Console.Write("Waiting for client connection...");
            pipeServer.WaitForConnection();

            Console.WriteLine("Client connected.");
            try
            {
                // Read user input and send that to the client process.
                using (StreamWriter sw = new StreamWriter(pipeServer))
                {
                    sw.AutoFlush = true;
                    Console.Write("Enter text: ");
                    sw.WriteLine(Console.ReadLine());
                }
            }
            // Catch the IOException that is raised if the pipe is broken
            // or disconnected.
            catch (IOException e)
            {
                Console.WriteLine("ERROR: {0}", e.Message);
            }
        }
    }
}

Demand

For full trust for the immediate caller. This member cannot be used by partially trusted code.

Universal Windows Platform
Available since 10
.NET Framework
Available since 3.5
Return to top
Show:
© 2016 Microsoft