NamedPipeClientStream Class
Exposes a Stream around a named pipe, which supports both synchronous and asynchronous read and write operations.
Assembly: System.Core (in System.Core.dll)
Note: |
|---|
The HostProtectionAttribute attribute applied to this type or member has the following Resources property value: MayLeakOnAbort. The HostProtectionAttribute does not affect desktop applications (which are typically started by double-clicking an icon, typing a command, or entering a URL in a browser). For more information, see the HostProtectionAttribute class or SQL Server Programming and Host Protection Attributes. |
Named pipes provide one-way or duplex pipes for communication between a pipe server and one or more pipe clients. Named pipes can be used for interprocess communication locally or over a network. A single pipe name can be shared by multiple NamedPipeClientStream objects.
Any process can act as either a named pipe server or client, or both.
Note For Windows XP Professional and Windows 2000 Server, the maximum number of pipes that are permitted to simultaneously connect over the network is ten.
The following example demonstrates a way to send a string from a parent process to a child process on the same computer using named pipes. This example creates a NamedPipeServerStream object in a parent process. The NamedPipeServerStream object has a PipeDirection value of Out. The server then waits for a NamedPipeClientStream object in a child process to connect to it. In this example, both processes are on the same computer and the NamedPipeClientStream object has a PipeDirection value of In. The parent process then sends a user-supplied string to the child process. The string is displayed to the console.
This example is for the client process, which connects to the server process. For the entire code sample, including the code for both the pipe client and server, see How to: Use Named Pipes to Communicate Between Processes over a Network.
Imports System 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
System.MarshalByRefObject
System.IO.Stream
System.IO.Pipes.PipeStream
System.IO.Pipes.NamedPipeClientStream
Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Note: