.NET Framework Class Library
NamedPipeServerStream Class

Exposes a Stream around a named pipe, supporting both synchronous and asynchronous read and write operations.

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

Visual Basic (Declaration)
<HostProtectionAttribute(SecurityAction.LinkDemand, MayLeakOnAbort := True)> _
Public NotInheritable Class NamedPipeServerStream _
    Inherits PipeStream
Visual Basic (Usage)
Dim instance As NamedPipeServerStream
C#
[HostProtectionAttribute(SecurityAction.LinkDemand, MayLeakOnAbort = true)]
public sealed class NamedPipeServerStream : PipeStream
Visual C++
[HostProtectionAttribute(SecurityAction::LinkDemand, MayLeakOnAbort = true)]
public ref class NamedPipeServerStream sealed : public PipeStream
JScript
public final class NamedPipeServerStream extends PipeStream
Remarks

NoteNote:

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 , the maximum number of pipes that are permitted to simultaneously connect over the network is ten.

Examples

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 with 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 server process, which uses the NamedPipeServerStream class. For the entire code example, including the code for both the pipe client and server, see How to: Use Named Pipes to Communicate Between Processes over a Network.

Visual Basic
Imports System
Imports System.IO
Imports System.IO.Pipes

Class PipeServer

    Shared Sub Main()
        Dim pipeServer As New NamedPipeServerStream("testpipe", PipeDirection.Out)

        Console.WriteLine("NamedPipeServerStream object created.")

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

        Console.WriteLine("Client connected.")
        Try
            'Read user input and send that to the client process.
            Dim sw As New StreamWriter(pipeServer)
            sw.AutoFlush = True
            Console.Write("Enter Text: ")
            sw.WriteLine(Console.ReadLine())
        Catch ex As IOException
            ' Catch the IOException that is raised if the pipe is broken
            ' or disconnected
            Console.WriteLine("ERROR: {0}", ex.Message)
        End Try
    End Sub
End Class
C#
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);
            }
        }
    }
}
Inheritance Hierarchy

System..::.Object
  System..::.MarshalByRefObject
    System.IO..::.Stream
      System.IO.Pipes..::.PipeStream
        System.IO.Pipes..::.NamedPipeServerStream
Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Platforms

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.
Version Information

.NET Framework

Supported in: 3.5
See Also

Reference

Tags :


Community Content

HalR
Create Named Pipe in PowerShell
[reflection.Assembly]::LoadWithPartialName("system.core")
$pipe = New-Object system.IO.Pipes.NamedPipeServerStream("PipeName")
    
  
Tags :

Page view tracker