AppModule.NamedPipes An abstract class, which defines the methods for creating named pipes connections, reading and writing data. This class is inherited by ClientPipeConnection and ServerPipeConnection classes, used for client and server applications respectively, which communicate using NamesPipes. A PipeHandle object containing the native pipe handle. The name of the named pipe. This name is used for creating a server pipe and connecting client ones to it. Boolean field used by the IDisposable implementation. The maximum bytes that will be read from the pipe connection. This field could be used if the maximum length of the client message is known and we want to implement some security, which prevents the server from reading larger messages. Reads a message from the pipe connection and converts it to a string using the UTF8 encoding. See the NamedPipeWrapper.Read method for an explanation of the message format. The UTF8 encoded string representation of the data. Reads a message from the pipe connection. See the NamedPipeWrapper.ReadBytes method for an explanation of the message format. The bytes read from the pipe connection. Writes a string to the pipe connection/ The text to write. Writes an array of bytes to the pipe connection. The bytes array. Closes the pipe connection. Connects a pipe connection. Disposes a pipe connection by closing the underlying native handle. Disposes a pipe connection by closing the underlying native handle. A boolean indicating how the method is called. Checks if the pipe connection is disposed. This check is done before performing any pipe operations. Gets the pipe connection state from the PipeHandle object. The pipe connection state. Retrieved the operating system native handle for the pipe connection. Used by client applications to communicate with server ones by using named pipes. The network name of the server where the server pipe is created. If "." is used as a server name then the pipe is connected to the local machine. Closes a client named pipe connection. A client pipe connection is closed by closing the underlying pipe handle. Connects a client pipe to an existing server one. Attempts to establish a connection to the a server named pipe. If the attempt is successful the method creates the PipeHandle object and assigns it to the Handle field.

This method is used when it is not known whether a server pipe already exists.
True if a connection is established.
Creates an instance of the ClientPipeConnection assuming that the server pipe is created on the same machine. The maximum bytes to read from the client is set to be Int32.MaxValue. The name of the server pipe. Creates an instance of the ClientPipeConnection specifying the network name of the server. The maximum bytes to read from the client is set to be Int32.MaxValue. The name of the server pipe. The network name of the machine, where the server pipe is created. Object destructor. This utility class exposes kernel32.dll methods for named pipes communication. Use the following links for complete information about the exposed methods: Named Pipe Functions File Management Functions Handle and Object Functions System Error Codes Creates an instance of a named pipe and returns a handle for subsequent pipe operations. Pointer to the null-terminated string that uniquely identifies the pipe. Pipe access mode, the overlapped mode, the write-through mode, and the security access mode of the pipe handle. Type, read, and wait modes of the pipe handle. Maximum number of instances that can be created for this pipe. Number of bytes to reserve for the output buffer. Number of bytes to reserve for the input buffer. Default time-out value, in milliseconds. Pointer to a SecurityAttributes object that specifies a security descriptor for the new named pipe. If the function succeeds, the return value is a handle to the server end of a named pipe instance. Enables a named pipe server process to wait for a client process to connect to an instance of a named pipe. Handle to the server end of a named pipe instance. Pointer to an Overlapped object. If the function succeeds, the return value is nonzero. Connects to a message-type pipe (and waits if an instance of the pipe is not available), writes to and reads from the pipe, and then closes the pipe. Pointer to a null-terminated string specifying the pipe name. Pointer to the buffer containing the data written to the pipe. Size of the write buffer, in bytes. Pointer to the buffer that receives the data read from the pipe. Size of the read buffer, in bytes. Pointer to a variable that receives the number of bytes read from the pipe. Number of milliseconds to wait for the named pipe to be available. If the function succeeds, the return value is nonzero. Creates or opens a file, directory, physical disk, volume, console buffer, tape drive, communications resource, mailslot, or named pipe. Pointer to a null-terminated string that specifies the name of the object to create or open. Access to the object (reading, writing, or both). Sharing mode of the object (reading, writing, both, or neither). Pointer to a SecurityAttributes object that determines whether the returned handle can be inherited by child processes. Action to take on files that exist, and which action to take when files do not exist. File attributes and flags. Handle to a template file, with the GENERIC_READ access right. If the function succeeds, the return value is an open handle to the specified file. Reads data from a file, starting at the position indicated by the file pointer. Handle to the file to be read. Pointer to the buffer that receives the data read from the file. Number of bytes to be read from the file. Pointer to the variable that receives the number of bytes read. Pointer to an Overlapped object. The ReadFile function returns when one of the following conditions is met: a write operation completes on the write end of the pipe, the number of bytes requested has been read, or an error occurs. Writes data to a file at the position specified by the file pointer. Handle to the file. Pointer to the buffer containing the data to be written to the file. Pointer to the variable that receives the number of bytes written. Pointer to an Overlapped object. If the function succeeds, the return value is nonzero. Retrieves information about a specified named pipe. Handle to the named pipe for which information is wanted. Pointer to a variable that indicates the current state of the handle. Pointer to a variable that receives the number of current pipe instances. Pointer to a variable that receives the maximum number of bytes to be collected on the client's computer before transmission to the server. Pointer to a variable that receives the maximum time, in milliseconds, that can pass before a remote named pipe transfers information over the network. Pointer to a buffer that receives the null-terminated string containing the user name string associated with the client application. Size of the buffer specified by the lpUserName parameter. If the function succeeds, the return value is nonzero. Cancels all pending input and output (I/O) operations that were issued by the calling thread for the specified file handle. Handle to a file. If the function succeeds, the return value is nonzero. Waits until either a time-out interval elapses or an instance of the specified named pipe is available for connection. Pointer to a null-terminated string that specifies the name of the named pipe. Number of milliseconds that the function will wait for an instance of the named pipe to be available. If an instance of the pipe is available before the time-out interval elapses, the return value is nonzero. Retrieves the calling thread's last-error code value. The return value is the calling thread's last-error code value. Flushes the buffers of the specified file and causes all buffered data to be written to the file. Handle to an open file. If the function succeeds, the return value is nonzero. Disconnects the server end of a named pipe instance from a client process. Handle to an instance of a named pipe. If the function succeeds, the return value is nonzero. Sets the read mode and the blocking mode of the specified named pipe. If the specified handle is to the client end of a named pipe and if the named pipe server process is on a remote computer, the function can also be used to control local buffering. Handle to the named pipe instance. Pointer to a variable that supplies the new mode. Pointer to a variable that specifies the maximum number of bytes collected on the client computer before transmission to the server. Pointer to a variable that specifies the maximum time, in milliseconds, that can pass before a remote named pipe transfers information over the network. If the function succeeds, the return value is nonzero. Closes an open object handle. Handle to an open object. If the function succeeds, the return value is nonzero. Closes an open object handle. Handle to an open object. If the function succeeds, the return value is nonzero. Sets the security descriptor attributes Reference to a SECURITY_DESCRIPTOR structure. Initializes a SECURITY_DESCRIPTOR structure. Private constructor. A utility class that exposes named pipes operations. This class uses the exposed exposed kernel32.dll methods by the NamedPipeNative class to provided controlled named pipe functionality. This exception is thrown by named pipes communication methods. Creates a NamedPipeIOException instance. The error message text. Creates a NamedPipeIOException instance. The error message text. The native error code. Creates a NamedPipeIOException instance. The serialization information. The streaming context. This utility class exposes kernel32.dll methods for named pipes communication. Use the following links for complete information about the exposed methods: Named Pipe Functions File Management Functions Handle and Object Functions System Error Codes Outbound pipe access. Duplex pipe access. Inbound pipe access. Pipe blocking mode. Pipe non-blocking mode. Pipe read mode of type Byte. Pipe read mode of type Message. Byte pipe type. Message pipe type. Pipe client end. Pipe server end. Unlimited server pipe instances. Waits indefinitely when connecting to a pipe. Does not wait for the named pipe. Uses the default time-out specified in a call to the CreateNamedPipe method. Generic write access to the pipe. Generic execute access to the pipe. Read, write, and execute access. Create new file. Fails if the file exists. Create new file. Overrides an existing file. Open existing file. Open existing file. If the file does not exist, creates it. Opens the file and truncates it so that its size is zero bytes. Invalid operating system handle. The operation completed successfully. The system cannot find the file specified. All pipe instances are busy. The pipe is being closed. No process is on the other end of the pipe. More data is available. There is a process on other end of the pipe. Waiting for a process to open the other end of the pipe. Creates an instance of a named pipe and returns a handle for subsequent pipe operations. Pointer to the null-terminated string that uniquely identifies the pipe. Pipe access mode, the overlapped mode, the write-through mode, and the security access mode of the pipe handle. Type, read, and wait modes of the pipe handle. Maximum number of instances that can be created for this pipe. Number of bytes to reserve for the output buffer. Number of bytes to reserve for the input buffer. Default time-out value, in milliseconds. Pointer to a SECURITY_ATTRIBUTES object that specifies a security descriptor for the new named pipe. If the function succeeds, the return value is a handle to the server end of a named pipe instance. Enables a named pipe server process to wait for a client process to connect to an instance of a named pipe. Handle to the server end of a named pipe instance. Pointer to an Overlapped object. If the function succeeds, the return value is nonzero. Connects to a message-type pipe (and waits if an instance of the pipe is not available), writes to and reads from the pipe, and then closes the pipe. Pointer to a null-terminated string specifying the pipe name. Pointer to the buffer containing the data written to the pipe. Size of the write buffer, in bytes. Pointer to the buffer that receives the data read from the pipe. Size of the read buffer, in bytes. Pointer to a variable that receives the number of bytes read from the pipe. Number of milliseconds to wait for the named pipe to be available. If the function succeeds, the return value is nonzero. Creates or opens a file, directory, physical disk, volume, console buffer, tape drive, communications resource, mailslot, or named pipe. Pointer to a null-terminated string that specifies the name of the object to create or open. Access to the object (reading, writing, or both). Sharing mode of the object (reading, writing, both, or neither). Pointer to a SecurityAttributes object that determines whether the returned handle can be inherited by child processes. Action to take on files that exist, and which action to take when files do not exist. File attributes and flags. Handle to a template file, with the GENERIC_READ access right. If the function succeeds, the return value is an open handle to the specified file. Reads data from a file, starting at the position indicated by the file pointer. Handle to the file to be read. Pointer to the buffer that receives the data read from the file. Number of bytes to be read from the file. Pointer to the variable that receives the number of bytes read. Pointer to an Overlapped object. The ReadFile function returns when one of the following conditions is met: a write operation completes on the write end of the pipe, the number of bytes requested has been read, or an error occurs. Writes data to a file at the position specified by the file pointer. Handle to the file. Pointer to the buffer containing the data to be written to the file. Pointer to the variable that receives the number of bytes written. Pointer to an Overlapped object. If the function succeeds, the return value is nonzero. Retrieves information about a specified named pipe. Handle to the named pipe for which information is wanted. Pointer to a variable that indicates the current state of the handle. Pointer to a variable that receives the number of current pipe instances. Pointer to a variable that receives the maximum number of bytes to be collected on the client's computer before transmission to the server. Pointer to a variable that receives the maximum time, in milliseconds, that can pass before a remote named pipe transfers information over the network. Pointer to a buffer that receives the null-terminated string containing the user name string associated with the client application. Size of the buffer specified by the lpUserName parameter. If the function succeeds, the return value is nonzero. Cancels all pending input and output (I/O) operations that were issued by the calling thread for the specified file handle. Handle to a file. If the function succeeds, the return value is nonzero. Waits until either a time-out interval elapses or an instance of the specified named pipe is available for connection. Pointer to a null-terminated string that specifies the name of the named pipe. Number of milliseconds that the function will wait for an instance of the named pipe to be available. If an instance of the pipe is available before the time-out interval elapses, the return value is nonzero. Retrieves the calling thread's last-error code value. The return value is the calling thread's last-error code value. Flushes the buffers of the specified file and causes all buffered data to be written to the file. Handle to an open file. If the function succeeds, the return value is nonzero. Disconnects the server end of a named pipe instance from a client process. Handle to an instance of a named pipe. If the function succeeds, the return value is nonzero. Sets the read mode and the blocking mode of the specified named pipe. If the specified handle is to the client end of a named pipe and if the named pipe server process is on a remote computer, the function can also be used to control local buffering. Handle to the named pipe instance. Pointer to a variable that supplies the new mode. Pointer to a variable that specifies the maximum number of bytes collected on the client computer before transmission to the server. Pointer to a variable that specifies the maximum time, in milliseconds, that can pass before a remote named pipe transfers information over the network. If the function succeeds, the return value is nonzero. Closes an open object handle. Handle to an open object. If the function succeeds, the return value is nonzero. Sets the security descriptor attributes Reference to a SECURITY_DESCRIPTOR structure. Initializes a SECURITY_DESCRIPTOR structure. Private constructor. Security Descriptor structure Security Attributes structure. This class is used as a dummy parameter only. This class is used as a dummy parameter only. A utility class that exposes named pipes operations. This class uses the exposed exposed kernel32.dll methods by the NamedPipeNative class to provided controlled named pipe functionality. The number of retries when creating a pipe or connecting to a pipe. Wait time for the NamedPipeNative.WaitNamedPipe operation. Reads a string from a named pipe using the UTF8 encoding. The pipe handle. The maximum bytes to read. A UTF8 string. This function uses AppModule.NamedPipes.ReadBytes to read the bytes from the pipe and then converts them to string.

The first four bytes of the pipe data are expected to contain the data length of the message. This method first reads those four bytes and converts them to integer. It then continues to read from the pipe using the extracted data length.
Reads the bytes from a named pipe. The pipe handle. The maximum bytes to read. An array of bytes. This method expects that the first four bytes in the pipe define the length of the data to read. If the data length is greater than maxBytes the method returns null.

The first four bytes of the pipe data are expected to contain the data length of the message. This method first reads those four bytes and converts them to integer. It then continues to read from the pipe using the extracted data length.
Writes a string to a named pipe. The pipe handle. The text to write to the pipe. This method converts the text into an array of bytes, using the UTF8 encoding and the uses AppModule.NamedPipes.WriteBytes to write to the pipe.

When writing to a pipe the method first writes four bytes that define the data length. It then writes the whole message.
Writes an array of bytes to a named pipe. The pipe handle. The bytes to write. If we try bytes array we attempt to write is empty then this method write a space character to the pipe. This is necessary because the other end of the pipe uses a blocking Read operation so we must write someting.

The bytes length is restricted by the maxBytes parameter, which is done primarily for security reasons.

When writing to a pipe the method first writes four bytes that define the data length. It then writes the whole message.
Tries to connect to a named pipe on the same machine. The name of the pipe. The resulting pipe handle. Return true if the attempt succeeds. This method is used mainly when stopping the pipe server. It unblocks the existing pipes, which wait for client connection. Tries to connect to a named pipe. The name of the pipe. The name of the server. The resulting pipe handle. Return true if the attempt succeeds. This method is used mainly when stopping the pipe server. It unblocks the existing pipes, which wait for client connection. Connects to a server named pipe on the same machine. The pipe name. The pipe handle, which also contains the pipe state. This method is used by clients to establish a pipe connection with a server pipe. Connects to a server named pipe. The pipe name. The server name. The pipe handle, which also contains the pipe state. This method is used by clients to establish a pipe connection with a server pipe. Creates a server named pipe. The name of the pipe. The size of the outbound buffer. The size of the inbound buffer. The pipe handle. Creates a server named pipe. The name of the pipe. The size of the outbound buffer. The size of the inbound buffer. Specifies whether to make the pipe secure. The pipe handle. You can specify a security descriptor for a named pipe when you call the CreateNamedPipe function. The security descriptor controls access to both client and server ends of the named pipe. If NULL is specified, the named pipe gets a default security descriptor. The ACLs in the default security descriptor for a named pipe grant full control to the LocalSystem account, administrators, and the creator owner. They also grant read access to members of the Everyone group and the anonymous account.

If the secure parameter is false the method creates a security descriptor that grants full access to Everyone.
Creates a SECURITY_DESCRIPTOR with DACL = null, which allows full access to Everyone. The SECURITY_DESCRIPTOR structure. Starts waiting for client connections. Blocks the current execution until a client pipe attempts to establish a connection. The pipe handle. Returns the number of instances of a named pipe. The pipe handle. The number of instances. Closes a named pipe and releases the native handle. The pipe handle. Flushes all the data in a named pipe. The pipe handle. Disconnects a server named pipe from the client. Server pipes can be reused by first disconnecting them from the client and then calling the Connect method to start listening. This improves the performance as it is not necessary to create new pipe handles. The pipe handle. Private constructor. Holds the operating system native handle and the current state of the pipe connection. The operating system native handle. The current state of the pipe connection. Creates a PipeHandle instance using the passed native handle. The native handle. Creates a PipeHandle instance using the provided native handle and state. The native handle. The state of the pipe connection. Creates a PipeHandle instance with an invalid native handle. Used by server applications to communicate with client ones by using named pipes. Disconnects a client named pipe. When a client named pipe is disconnected, the server one is not closed. The latter can later be reused by starting to listen again.

In a message oriented protocol the server will disconnect the client when the response is sent and all the data is flushed. The same server named pipe could then be reused by calling the Connect method.
Closes the operating system native handle of the named pipe. Starts listening to client pipe connections. This method will block the program execution until a client pipe attempts to establish a connection.

When a client named pipe is disconnected, the server one is not closed. The latter can later be reused by starting to listen again.

Creates a ServerPipeConnection instance and the underlying operating system handle. The name of the pipe. The outbound buffer. The inbound buffer. The maximum bytes to read from clients. Creates a ServerPipeConnection instance and the underlying operating system handle. The name of the pipe. The outbound buffer. The inbound buffer. Specifies whether the pipe is secure. The maximum bytes to read from clients. If the secure parameter is true the default security descriptor is used. The ACLs in the default security descriptor for a named pipe grant full control to the LocalSystem account, administrators, and the creator owner. They also grant read access to members of the Everyone group and the anonymous account.

If the secure parameter is false the method creates a security descriptor that grants full access to Everyone.
Object destructor.