NamedPipeClientStream Constructors

Definition

Initializes a new instance of the NamedPipeClientStream class.

Overloads

NamedPipeClientStream(String)

Initializes a new instance of the NamedPipeClientStream class with the specified pipe name.

NamedPipeClientStream(String, String)

Initializes a new instance of the NamedPipeClientStream class with the specified pipe and server names.

NamedPipeClientStream(String, String, PipeDirection)

Initializes a new instance of the NamedPipeClientStream class with the specified pipe and server names, and the specified pipe direction.

NamedPipeClientStream(PipeDirection, Boolean, Boolean, SafePipeHandle)

Initializes a new instance of the NamedPipeClientStream class for the specified pipe handle with the specified pipe direction.

NamedPipeClientStream(String, String, PipeDirection, PipeOptions)

Initializes a new instance of the NamedPipeClientStream class with the specified pipe and server names, and the specified pipe direction and pipe options.

NamedPipeClientStream(String, String, PipeDirection, PipeOptions, TokenImpersonationLevel)

Initializes a new instance of the NamedPipeClientStream class with the specified pipe and server names, and the specified pipe direction, pipe options, and security impersonation level.

NamedPipeClientStream(String, String, PipeAccessRights, PipeOptions, TokenImpersonationLevel, HandleInheritability)

Initializes a new instance of the NamedPipeClientStream class with the specified pipe and server names, and the specified pipe options, security impersonation level, and inheritability mode.

NamedPipeClientStream(String, String, PipeDirection, PipeOptions, TokenImpersonationLevel, HandleInheritability)

Initializes a new instance of the NamedPipeClientStream class with the specified pipe and server names, and the specified pipe direction, pipe options, security impersonation level, and inheritability mode.

NamedPipeClientStream(String)

Initializes a new instance of the NamedPipeClientStream class with the specified pipe name.

public:
 NamedPipeClientStream(System::String ^ pipeName);
public NamedPipeClientStream (string pipeName);
new System.IO.Pipes.NamedPipeClientStream : string -> System.IO.Pipes.NamedPipeClientStream
Public Sub New (pipeName As String)

Parameters

pipeName
String

The name of the pipe.

Exceptions

pipeName is null.

pipeName is a zero-length string.

pipeName is set to "anonymous".

Remarks

This constructor uses the following default values:

NamedPipeClientStream(String, String)

Initializes a new instance of the NamedPipeClientStream class with the specified pipe and server names.

public:
 NamedPipeClientStream(System::String ^ serverName, System::String ^ pipeName);
public NamedPipeClientStream (string serverName, string pipeName);
new System.IO.Pipes.NamedPipeClientStream : string * string -> System.IO.Pipes.NamedPipeClientStream
Public Sub New (serverName As String, pipeName As String)

Parameters

serverName
String

The name of the remote computer to connect to, or "." to specify the local computer.

pipeName
String

The name of the pipe.

Exceptions

pipeName or serverName is null.

pipeName or serverName is a zero-length string.

pipeName is set to "anonymous".

Remarks

This constructor uses the following default values:

NamedPipeClientStream(String, String, PipeDirection)

Initializes a new instance of the NamedPipeClientStream class with the specified pipe and server names, and the specified pipe direction.

public:
 NamedPipeClientStream(System::String ^ serverName, System::String ^ pipeName, System::IO::Pipes::PipeDirection direction);
public NamedPipeClientStream (string serverName, string pipeName, System.IO.Pipes.PipeDirection direction);
new System.IO.Pipes.NamedPipeClientStream : string * string * System.IO.Pipes.PipeDirection -> System.IO.Pipes.NamedPipeClientStream
Public Sub New (serverName As String, pipeName As String, direction As PipeDirection)

Parameters

serverName
String

The name of the remote computer to connect to, or "." to specify the local computer.

pipeName
String

The name of the pipe.

direction
PipeDirection

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

Exceptions

pipeName or serverName is null.

pipeName or serverName is a zero-length string.

pipeName is set to "anonymous".

-or-

direction is not a valid PipeDirection value.

Examples

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 NamedPipeClientStream object in a child process, which then connects to a pipe on the local computer. The server example can be seen in the NamedPipeServerStream class. This example is part of a larger example provided for the NamedPipeServerStream and NamedPipeClientStream classes.

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

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

            // 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();
    }
}
Imports System.IO
Imports System.IO.Pipes
Imports System.Security.Principal

Class PipeClient

    Shared Sub Main(ByVal args As String())

        Dim pipeClient As New NamedPipeClientStream("localhost", _
                    "testpipe", PipeDirection.In, PipeOptions.None)

        ' Connect to the pipe or wait until the pipe is available.
        Console.WriteLine("Attempting to connect to the pipe...")
        pipeClient.Connect()

        Console.WriteLine("Connect to the pipe.")
        Console.WriteLine("There are currently {0} pipe server instances open.", _
                          pipeClient.NumberOfServerInstances)

        Dim sr As New StreamReader(pipeClient)
        Dim temp As String

        temp = sr.ReadLine()
        While Not temp Is Nothing
            Console.WriteLine("Received from server: {0}", temp)
            temp = sr.ReadLine()
        End While
        Console.Write("Press Enter to continue...")
        Console.ReadLine()
    End Sub
End Class

Remarks

This constructor uses the following default values:

NamedPipeClientStream(PipeDirection, Boolean, Boolean, SafePipeHandle)

Initializes a new instance of the NamedPipeClientStream class for the specified pipe handle with the specified pipe direction.

public:
 NamedPipeClientStream(System::IO::Pipes::PipeDirection direction, bool isAsync, bool isConnected, Microsoft::Win32::SafeHandles::SafePipeHandle ^ safePipeHandle);
public NamedPipeClientStream (System.IO.Pipes.PipeDirection direction, bool isAsync, bool isConnected, Microsoft.Win32.SafeHandles.SafePipeHandle safePipeHandle);
[System.Security.SecurityCritical]
public NamedPipeClientStream (System.IO.Pipes.PipeDirection direction, bool isAsync, bool isConnected, Microsoft.Win32.SafeHandles.SafePipeHandle safePipeHandle);
new System.IO.Pipes.NamedPipeClientStream : System.IO.Pipes.PipeDirection * bool * bool * Microsoft.Win32.SafeHandles.SafePipeHandle -> System.IO.Pipes.NamedPipeClientStream
[<System.Security.SecurityCritical>]
new System.IO.Pipes.NamedPipeClientStream : System.IO.Pipes.PipeDirection * bool * bool * Microsoft.Win32.SafeHandles.SafePipeHandle -> System.IO.Pipes.NamedPipeClientStream
Public Sub New (direction As PipeDirection, isAsync As Boolean, isConnected As Boolean, safePipeHandle As SafePipeHandle)

Parameters

direction
PipeDirection

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

isAsync
Boolean

true to indicate that the handle was opened asynchronously; otherwise, false.

isConnected
Boolean

true to indicate that the pipe is connected; otherwise, false.

safePipeHandle
SafePipeHandle

A safe handle for the pipe that this NamedPipeClientStream object will encapsulate.

Attributes

Exceptions

The stream has been closed.

safePipeHandle is not a valid handle.

safePipeHandle is null.

direction is not a valid PipeDirection value.

NamedPipeClientStream(String, String, PipeDirection, PipeOptions)

Initializes a new instance of the NamedPipeClientStream class with the specified pipe and server names, and the specified pipe direction and pipe options.

public:
 NamedPipeClientStream(System::String ^ serverName, System::String ^ pipeName, System::IO::Pipes::PipeDirection direction, System::IO::Pipes::PipeOptions options);
public NamedPipeClientStream (string serverName, string pipeName, System.IO.Pipes.PipeDirection direction, System.IO.Pipes.PipeOptions options);
new System.IO.Pipes.NamedPipeClientStream : string * string * System.IO.Pipes.PipeDirection * System.IO.Pipes.PipeOptions -> System.IO.Pipes.NamedPipeClientStream
Public Sub New (serverName As String, pipeName As String, direction As PipeDirection, options As PipeOptions)

Parameters

serverName
String

The name of the remote computer to connect to, or "." to specify the local computer.

pipeName
String

The name of the pipe.

direction
PipeDirection

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

options
PipeOptions

One of the enumeration values that determines how to open or create the pipe.

Exceptions

pipeName or serverName is null.

pipeName or serverName is a zero-length string.

pipeName is set to "anonymous".

-or-

direction is not a valid PipeDirection value.

-or-

options is not a valid PipeOptions value.

Remarks

This constructor uses the following default values:

NamedPipeClientStream(String, String, PipeDirection, PipeOptions, TokenImpersonationLevel)

Initializes a new instance of the NamedPipeClientStream class with the specified pipe and server names, and the specified pipe direction, pipe options, and security impersonation level.

public:
 NamedPipeClientStream(System::String ^ serverName, System::String ^ pipeName, System::IO::Pipes::PipeDirection direction, System::IO::Pipes::PipeOptions options, System::Security::Principal::TokenImpersonationLevel impersonationLevel);
public NamedPipeClientStream (string serverName, string pipeName, System.IO.Pipes.PipeDirection direction, System.IO.Pipes.PipeOptions options, System.Security.Principal.TokenImpersonationLevel impersonationLevel);
new System.IO.Pipes.NamedPipeClientStream : string * string * System.IO.Pipes.PipeDirection * System.IO.Pipes.PipeOptions * System.Security.Principal.TokenImpersonationLevel -> System.IO.Pipes.NamedPipeClientStream
Public Sub New (serverName As String, pipeName As String, direction As PipeDirection, options As PipeOptions, impersonationLevel As TokenImpersonationLevel)

Parameters

serverName
String

The name of the remote computer to connect to, or "." to specify the local computer.

pipeName
String

The name of the pipe.

direction
PipeDirection

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

options
PipeOptions

One of the enumeration values that determines how to open or create the pipe.

impersonationLevel
TokenImpersonationLevel

One of the enumeration values that determines the security impersonation level.

Exceptions

pipeName or serverName is null.

pipeName or serverName is a zero-length string.

pipeName is set to "anonymous".

-or-

direction is not a valid PipeDirection value.

-or-

options is not a valid PipeOptions value.

-or-

impersonationLevel is not a valid TokenImpersonationLevel value.

Remarks

This constructor uses a default HandleInheritability value of None.

NamedPipeClientStream(String, String, PipeAccessRights, PipeOptions, TokenImpersonationLevel, HandleInheritability)

Initializes a new instance of the NamedPipeClientStream class with the specified pipe and server names, and the specified pipe options, security impersonation level, and inheritability mode.

public:
 NamedPipeClientStream(System::String ^ serverName, System::String ^ pipeName, System::IO::Pipes::PipeAccessRights desiredAccessRights, System::IO::Pipes::PipeOptions options, System::Security::Principal::TokenImpersonationLevel impersonationLevel, System::IO::HandleInheritability inheritability);
public NamedPipeClientStream (string serverName, string pipeName, System.IO.Pipes.PipeAccessRights desiredAccessRights, System.IO.Pipes.PipeOptions options, System.Security.Principal.TokenImpersonationLevel impersonationLevel, System.IO.HandleInheritability inheritability);
new System.IO.Pipes.NamedPipeClientStream : string * string * System.IO.Pipes.PipeAccessRights * System.IO.Pipes.PipeOptions * System.Security.Principal.TokenImpersonationLevel * System.IO.HandleInheritability -> System.IO.Pipes.NamedPipeClientStream
Public Sub New (serverName As String, pipeName As String, desiredAccessRights As PipeAccessRights, options As PipeOptions, impersonationLevel As TokenImpersonationLevel, inheritability As HandleInheritability)

Parameters

serverName
String

The name of the remote computer to connect to, or "." to specify the local computer.

pipeName
String

The name of the pipe.

desiredAccessRights
PipeAccessRights

One of the enumeration values that specifies the desired access rights of the pipe.

options
PipeOptions

One of the enumeration values that determines how to open or create the pipe.

impersonationLevel
TokenImpersonationLevel

One of the enumeration values that determines the security impersonation level.

inheritability
HandleInheritability

One of the enumeration values that determines whether the underlying handle will be inheritable by child processes.

Exceptions

pipeName or serverName is null.

pipeName or serverName is a zero-length string.

pipeName is set to "anonymous".

-or-

options is not a valid PipeOptions value.

-or-

impersonationLevel is not a valid TokenImpersonationLevel value.

-or-

inheritability is not a valid HandleInheritability value.

Remarks

The pipe direction for this constructor is determined by the desiredAccessRights parameter. If the desiredAccessRights value is ReadData, the pipe direction will be In. If the value of desiredAccessRights is WriteData, the pipe direction will be Out. If the value of desiredAccessRights includes both ReadData and WriteData, the pipe direction will be InOut.

NamedPipeClientStream(String, String, PipeDirection, PipeOptions, TokenImpersonationLevel, HandleInheritability)

Initializes a new instance of the NamedPipeClientStream class with the specified pipe and server names, and the specified pipe direction, pipe options, security impersonation level, and inheritability mode.

public:
 NamedPipeClientStream(System::String ^ serverName, System::String ^ pipeName, System::IO::Pipes::PipeDirection direction, System::IO::Pipes::PipeOptions options, System::Security::Principal::TokenImpersonationLevel impersonationLevel, System::IO::HandleInheritability inheritability);
public NamedPipeClientStream (string serverName, string pipeName, System.IO.Pipes.PipeDirection direction, System.IO.Pipes.PipeOptions options, System.Security.Principal.TokenImpersonationLevel impersonationLevel, System.IO.HandleInheritability inheritability);
new System.IO.Pipes.NamedPipeClientStream : string * string * System.IO.Pipes.PipeDirection * System.IO.Pipes.PipeOptions * System.Security.Principal.TokenImpersonationLevel * System.IO.HandleInheritability -> System.IO.Pipes.NamedPipeClientStream
Public Sub New (serverName As String, pipeName As String, direction As PipeDirection, options As PipeOptions, impersonationLevel As TokenImpersonationLevel, inheritability As HandleInheritability)

Parameters

serverName
String

The name of the remote computer to connect to, or "." to specify the local computer.

pipeName
String

The name of the pipe.

direction
PipeDirection

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

options
PipeOptions

One of the enumeration values that determines how to open or create the pipe.

impersonationLevel
TokenImpersonationLevel

One of the enumeration values that determines the security impersonation level.

inheritability
HandleInheritability

One of the enumeration values that determines whether the underlying handle will be inheritable by child processes.

Exceptions

pipeName or serverName is null.

pipeName or serverName is a zero-length string.

pipeName is set to "anonymous".

-or-

direction is not a valid PipeDirection value.

-or-

options is not a valid PipeOptions value.

-or-

impersonationLevel is not a valid TokenImpersonationLevel value.

-or-

inheritability is not a valid HandleInheritability value.

Applies to