0 out of 1 rated this helpful - Rate this topic

NamedPipeServerStream Class

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

System.Object
  System.MarshalByRefObject
    System.IO.Stream
      System.IO.Pipes.PipeStream
        System.IO.Pipes.NamedPipeServerStream

Namespace:  System.IO.Pipes
Assembly:  System.Core (in System.Core.dll)
[HostProtectionAttribute(SecurityAction.LinkDemand, MayLeakOnAbort = true)]
public sealed class NamedPipeServerStream : PipeStream

The NamedPipeServerStream type exposes the following members.

  Name Description
Public method NamedPipeServerStream(String) Initializes a new instance of the NamedPipeServerStream class with the specified pipe name.
Public method NamedPipeServerStream(String, PipeDirection) Initializes a new instance of the NamedPipeServerStream class with the specified pipe name and pipe direction.
Public method NamedPipeServerStream(String, PipeDirection, Int32) Initializes a new instance of the NamedPipeServerStream class with the specified pipe name, pipe direction, and maximum number of server instances.
Public method NamedPipeServerStream(PipeDirection, Boolean, Boolean, SafePipeHandle) Initializes a new instance of the NamedPipeServerStream class from the specified pipe handle.
Public method NamedPipeServerStream(String, PipeDirection, Int32, PipeTransmissionMode) Initializes a new instance of the NamedPipeServerStream class with the specified pipe name, pipe direction, maximum number of server instances, and transmission mode.
Public method NamedPipeServerStream(String, PipeDirection, Int32, PipeTransmissionMode, PipeOptions) Initializes a new instance of the NamedPipeServerStream class with the specified pipe name, pipe direction, maximum number of server instances, transmission mode, and pipe options.
Public method NamedPipeServerStream(String, PipeDirection, Int32, PipeTransmissionMode, PipeOptions, Int32, Int32) Initializes a new instance of the NamedPipeServerStream class with the specified pipe name, pipe direction, maximum number of server instances, transmission mode, pipe options, and recommended in and out buffer sizes.
Public method NamedPipeServerStream(String, PipeDirection, Int32, PipeTransmissionMode, PipeOptions, Int32, Int32, PipeSecurity) Initializes a new instance of the NamedPipeServerStream class with the specified pipe name, pipe direction, maximum number of server instances, transmission mode, pipe options, recommended in and out buffer sizes, and pipe security.
Public method NamedPipeServerStream(String, PipeDirection, Int32, PipeTransmissionMode, PipeOptions, Int32, Int32, PipeSecurity, HandleInheritability) Initializes a new instance of the NamedPipeServerStream class with the specified pipe name, pipe direction, maximum number of server instances, transmission mode, pipe options, recommended in and out buffer sizes, pipe security, and inheritability mode.
Public method NamedPipeServerStream(String, PipeDirection, Int32, PipeTransmissionMode, PipeOptions, Int32, Int32, PipeSecurity, HandleInheritability, PipeAccessRights) Initializes a new instance of the NamedPipeServerStream class with the specified pipe name, pipe direction, maximum number of server instances, transmission mode, pipe options, recommended in and out buffer sizes, pipe security, inheritability mode, and pipe access rights.
Top
  Name Description
Public property CanRead Gets a value indicating whether the current stream supports read operations. (Inherited from PipeStream.)
Public property CanSeek Gets a value indicating whether the current stream supports seek operations. (Inherited from PipeStream.)
Public property CanTimeout Gets a value that determines whether the current stream can time out. (Inherited from Stream.)
Public property CanWrite Gets a value indicating whether the current stream supports write operations. (Inherited from PipeStream.)
Public property InBufferSize Gets the size, in bytes, of the inbound buffer for a pipe. (Inherited from PipeStream.)
Public property IsAsync Gets a value indicating whether a PipeStream object was opened asynchronously or synchronously. (Inherited from PipeStream.)
Public property IsConnected Gets or sets a value indicating whether a PipeStream object is connected. (Inherited from PipeStream.)
Protected property IsHandleExposed Gets a value indicating whether a handle to a PipeStream object is exposed. (Inherited from PipeStream.)
Public property IsMessageComplete Gets a value indicating whether there is more data in the message returned from the most recent read operation. (Inherited from PipeStream.)
Public property Length Gets the length of a stream, in bytes. (Inherited from PipeStream.)
Public property OutBufferSize Gets the size, in bytes, of the outbound buffer for a pipe. (Inherited from PipeStream.)
Public property Position Gets or sets the current position of the current stream. (Inherited from PipeStream.)
Public property ReadMode Gets or sets the reading mode for a PipeStream object. (Inherited from PipeStream.)
Public property ReadTimeout Gets or sets a value, in miliseconds, that determines how long the stream will attempt to read before timing out. (Inherited from Stream.)
Public property SafePipeHandle Gets the safe handle for the local end of the pipe that the current PipeStream object encapsulates. (Inherited from PipeStream.)
Public property TransmissionMode Gets the pipe transmission mode supported by the current pipe. (Inherited from PipeStream.)
Public property WriteTimeout Gets or sets a value, in miliseconds, that determines how long the stream will attempt to write before timing out. (Inherited from Stream.)
Top
  Name Description
Public method BeginRead Begins an asynchronous read operation. (Inherited from PipeStream.)
Public method BeginWaitForConnection Begins an asynchronous operation to wait for a client to connect.
Public method BeginWrite Begins an asynchronous write operation. (Inherited from PipeStream.)
Protected method CheckPipePropertyOperations Infrastructure. Verifies that the pipe is in a proper state for getting or setting properties. (Inherited from PipeStream.)
Protected method CheckReadOperations Infrastructure. Verifies that the pipe is in a connected state for read operations. (Inherited from PipeStream.)
Protected method CheckWriteOperations Infrastructure. Verifies that the pipe is in a connected state for write operations. (Inherited from PipeStream.)
Public method Close Closes the current stream and releases any resources (such as sockets and file handles) associated with the current stream. (Inherited from Stream.)
Public method CopyTo(Stream) Reads the bytes from the current stream and writes them to the destination stream. (Inherited from Stream.)
Public method CopyTo(Stream, Int32) Reads all the bytes from the current stream and writes them to a destination stream, using a specified buffer size. (Inherited from Stream.)
Public method CreateObjRef Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.)
Protected method CreateWaitHandle Obsolete. Allocates a WaitHandle object. (Inherited from Stream.)
Public method Disconnect Disconnects the current connection.
Public method Dispose() Releases all resources used by the Stream. (Inherited from Stream.)
Protected method Dispose(Boolean) Releases the unmanaged resources used by the PipeStream class and optionally releases the managed resources. (Inherited from PipeStream.)
Public method EndRead Ends a pending asynchronous read request. (Inherited from PipeStream.)
Public method EndWaitForConnection Ends an asynchronous operation to wait for a client to connect.
Public method EndWrite Ends a pending asynchronous write request. (Inherited from PipeStream.)
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method Flush Clears the buffer for the current stream and causes any buffered data to be written to the underlying device. (Inherited from PipeStream.)
Public method GetAccessControl Gets a PipeSecurity object that encapsulates the access control list (ACL) entries for the pipe described by the current PipeStream object. (Inherited from PipeStream.)
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetImpersonationUserName Gets the user name of the client on the other end of the pipe.
Public method GetLifetimeService Retrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method InitializeHandle Initializes a PipeStream object from the specified SafePipeHandle object. (Inherited from PipeStream.)
Public method InitializeLifetimeService Obtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Protected method MemberwiseClone() Creates a shallow copy of the current Object. (Inherited from Object.)
Protected method MemberwiseClone(Boolean) Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.)
Protected method ObjectInvariant Infrastructure. Provides support for a Contract. (Inherited from Stream.)
Public method Read Reads a block of bytes from a stream and writes the data to a specified buffer. (Inherited from PipeStream.)
Public method ReadByte Reads a byte from a pipe. (Inherited from PipeStream.)
Public method RunAsClient Calls a delegate while impersonating the client.
Public method Seek Sets the current position of the current stream to the specified value. (Inherited from PipeStream.)
Public method SetAccessControl Applies the access control list (ACL) entries specified by a PipeSecurity object to the pipe specified by the current PipeStream object. (Inherited from PipeStream.)
Public method SetLength Sets the length of the current stream to the specified value. (Inherited from PipeStream.)
Public method ToString Returns a string that represents the current object. (Inherited from Object.)
Public method WaitForConnection Waits for a client to connect to this NamedPipeServerStream object.
Public method WaitForPipeDrain Waits for the other end of the pipe to read all sent bytes. (Inherited from PipeStream.)
Public method Write Writes a block of bytes to the current stream using data from a buffer. (Inherited from PipeStream.)
Public method WriteByte Writes a byte to the current stream. (Inherited from PipeStream.)
Top
  Name Description
Public field Static member MaxAllowedServerInstances Represents the maximum number of server instances that the system resources allow.
Top

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 Note

For Windows XP Professional and Windows 2000 Server, a maximum of 10 pipes can simultaneously connect over the network.

Note 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.

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.


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);
            }
        }
    }
}


.NET Framework

Supported in: 4, 3.5

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ