NamedPipeServerStream 类
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
围绕命名管道公开 Stream,支持同步和异步读取和写入操作。
public ref class NamedPipeServerStream sealed : System::IO::Pipes::PipeStream
public sealed class NamedPipeServerStream : System.IO.Pipes.PipeStream
type NamedPipeServerStream = class
inherit PipeStream
Public NotInheritable Class NamedPipeServerStream
Inherits PipeStream
- 继承
- 继承
以下示例演示如何使用命名管道将字符串从父进程发送到同一计算机上的子进程。 此示例在父进程中创建一个 NamedPipeServerStream 对象,其 PipeDirection 值为 Out。然后,服务器将等待子进程中 NamedPipeClientStream 对象连接到该对象。 在此示例中,这两个进程位于同一台计算机上,NamedPipeClientStream 对象具有 PipeDirection 值 In。 然后,父进程将用户提供的字符串发送到子进程。 字符串会显示到控制台。
此示例适用于使用 NamedPipeServerStream 类的服务器进程。 有关整个代码示例(包括管道客户端和服务器的代码)请参阅 如何:将命名管道用于网络进程间通信。
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);
}
}
}
}
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
命名管道提供单向或双工管道,用于管道服务器与一个或多个管道客户端之间的通信。 命名管道可用于本地或通过网络进行进程间通信。 单个管道名称可由多个 NamedPipeClientStream 对象共享。
任何进程都可以充当命名管道服务器或客户端,也可以同时充当这两者。
Max |
表示系统资源允许的最大服务器实例数。 |
Can |
获取一个值,该值指示当前流是否支持读取操作。 (继承自 PipeStream) |
Can |
获取一个值,该值指示当前流是否支持查找操作。 (继承自 PipeStream) |
Can |
获取一个值,该值确定当前流是否可以超时。 (继承自 Stream) |
Can |
获取一个值,该值指示当前流是否支持写入操作。 (继承自 PipeStream) |
In |
获取管道的入站缓冲区的大小(以字节为单位)。 (继承自 PipeStream) |
Is |
获取一个值,该值指示 PipeStream 对象是异步打开还是同步打开。 (继承自 PipeStream) |
Is |
获取或设置一个值,该值指示 PipeStream 对象是否已连接。 (继承自 PipeStream) |
Is |
获取一个值,该值指示是否公开 PipeStream 对象的句柄。 (继承自 PipeStream) |
Is |
获取一个值,该值指示从最近的读取操作返回的消息中是否有更多数据。 (继承自 PipeStream) |
Length |
获取流的长度(以字节为单位)。 (继承自 PipeStream) |
Out |
获取管道的出站缓冲区的大小(以字节为单位)。 (继承自 PipeStream) |
Position |
获取或设置当前流的当前位置。 (继承自 PipeStream) |
Read |
获取或设置 PipeStream 对象的读取模式。 (继承自 PipeStream) |
Read |
获取或设置一个值(以毫秒为单位),该值确定流在超时前尝试读取的时间。 (继承自 Stream) |
Safe |
获取当前 PipeStream 对象封装的管道的本地端的安全句柄。 (继承自 PipeStream) |
Transmission |
获取当前管道支持的管道传输模式。 (继承自 PipeStream) |
Write |
获取或设置一个值(以毫秒为单位),该值确定流在超时之前尝试写入的时间。 (继承自 Stream) |
Copy |
使用取消令牌从 Stream 异步读取字节并将其写入指定的 PipeWriter。 |
Get |
返回管道流的安全信息。 |
Set |
更改现有管道流的安全属性。 |
Configure |
配置如何执行从异步可释放项返回的任务的 await。 |
产品 | 版本 |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |