AnonymousPipeClientStream Class
Exposes the client side of an anonymous pipe stream, 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. |
Anonymous pipes help provide safe and secure interprocess communication between child and parent processes. The AnonymousPipeClientStream class enables a child process to connect to and exchange information with a parent process.
Anonymous pipes are unnamed, one-way pipes that typically transfer data between parent and child processes. Anonymous pipes are always local; they cannot be used over a network. A PipeDirection value of InOut is not supported because anonymous pipes are defined to be one-way.
Anonymous pipes do not support Message read modes.
The client side of an anonymous pipe must be created from a pipe handle provided by the server side by calling the GetClientHandleAsString method. The string is then passed as a parameter when creating the client process. From the client process, it is passed to the AnonymousPipeClientStream constructor as the pipeHandleAsString parameter.
Note: |
|---|
For , a maximum of 10 pipes can simultaneously connect over the network. |
The following example demonstrates a way to send a string from a parent process to a child process by using anonymous pipes. This example creates an AnonymousPipeServerStream object in a parent process with a PipeDirection value of Out. It also creates an AnonymousPipeClientStream object in a child process with 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 is started by the server process. Name the resulting executable from the client code pipeClient.exe and copy it to the same directory as the server executable when you run this example. For the entire code example, including the code for both the pipe client and server, see How to: Use Anonymous Pipes to Communicate Between Local Processes.
Imports System Imports System.IO Imports System.IO.Pipes Class PipeClient Shared Sub Main(args() as String) If args.Length > 0 Then Using pipeClient As New AnonymousPipeClientStream(PipeDirection.In, args(0)) ' Show that anonymous Pipes do not support Message mode. Try Console.WriteLine("[CLIENT] Setting ReadMode to ""Message"".") pipeClient.ReadMode = PipeTransmissionMode.Message Catch e As NotSupportedException Console.WriteLine("[CLIENT] Execption:" + vbNewLine + " {0}", e.Message) End Try Console.WriteLine("[CLIENT] Current TransmissionMode: {0}.", _ pipeClient.TransmissionMode) Using sr As New StreamReader(pipeClient) ' Display the read text to the console Dim temp As String ' Wait for 'sync message' from the server. Do Console.WriteLine("[CLIENT] Wait for sync...") temp = sr.ReadLine() Loop While temp.StartsWith("SYNC") = False ' Read the server data and echo to the console. temp = sr.ReadLine() While Not temp = Nothing Console.WriteLine("[CLIENT] Echo: " + temp) temp = sr.ReadLine() End While End Using End Using End If Console.Write("[CLIENT] Press Enter to continue...") Console.ReadLine() End Sub End Class
System.MarshalByRefObject
System.IO.Stream
System.IO.Pipes.PipeStream
System.IO.Pipes.AnonymousPipeClientStream
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: