PipeTransmissionMode.Message:如何.NET命名管道的消息之间的区别? [英] PipeTransmissionMode.Message: How do .NET named pipes distinguish between messages?

查看:1170
本文介绍了PipeTransmissionMode.Message:如何.NET命名管道的消息之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以明确的含义<一href="http://msdn.microsoft.com/en-us/library/system.io.pipes.pipetransmissionmode.aspx"><$c$c>PipeTransmissionMode.Message在.NET?

Can somebody clarify the meaning of PipeTransmissionMode.Message in .NET?

如何.NET从另一个区分通过管道传递一个消息?

How does .NET distinguish one message passed through the pipe from another?

  • 我可以序列化使用<一个对象href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.formatters.binary.binaryformatter.aspx"><$c$c>BinaryFormatter然后通过配管作为消息传递给它?
  • 或者,只允许字符串的邮件时,管道处于 PipeTransmissionMode.Message 模式?
  • Can I serialize an object using a BinaryFormatter and then pass it through the pipe as a message?
  • Or are only string messages allowed when the pipe is in PipeTransmissionMode.Message mode?

推荐答案

管道传输模式是Windows操作系统的概念,而不是一个.NET概念。如果管道是在消息模式下创建的,每一次写入由发送者将被视为一个单独的消息的管道。接收器可从管道中读取或者:

The pipe transmission mode is a Windows operating system concept, not a .NET concept. If a pipe is created in Message mode, each write to the pipe by the sender is treated as a separate message. The receiver can read from the pipe either:

  • 在字节模式下,当数据被从管道中读出一个字节流,完全无视隐含的信息界限;或
  • 在消息模式中,当数据被读取作为消息流,在某种意义上说,任何读操作将只接收与一个单独的消息的字节,和一个特殊的错误code为通过本地API以指示是否返回有对于同样的信息继续接收字节。

这个功能的.NET包装,如浮出水面的 System.IO.Pipes 命名空间,如下底层的本机模式相当接近:

The .NET wrapping of this functionality, as surfaced in the System.IO.Pipes namespace, follows the underlying native model fairly closely:

  • 消息边界仍 通过调用由发送者所提出的模式确定 PipeStream.Write() PipeStream.WriteByte() - 数据 写在每个呼叫被视为不同 消息;
  • 接收器可以设置 ReadMode PipeTransmissionMode.Message ,然后每次调用 PipeStream.Read() PipeStream.ReadByte ()将会从目前的信息数据的下一块,直到 PipeStream.IsMessageComplete 修改其值为true,表示所有字节该消息已读
  • message boundaries are still determined by the pattern of calls made by the sender to PipeStream.Write() or PipeStream.WriteByte() - the data written in each call is treated as a distinct message;
  • the receiver can set ReadMode to PipeTransmissionMode.Message, and then every call to PipeStream.Read() or PipeStream.ReadByte() will read the next chunk of data from the current message, until the value of PipeStream.IsMessageComplete changes to true, indicating that all the bytes for that message have been read

所有的读取和写入的字节或字节数组方面进行。您可以发送任何字节你喜欢下来的管道。该TransmissionMode对此没有任何影响。

All reads and writes are done in terms of bytes or arrays of bytes. You can send whatever bytes you like down a pipe. The TransmissionMode has no bearing on this.

所以,是的,你可以发送一个序列化对象作为消息,前提是你写的连载再presentation到管道的所有字节为 PipeStream.Write一个呼叫()

So, yes, you can send a serialized object as a message, provided you write all the bytes of its serialized representation to the pipe in a single call to PipeStream.Write().

这篇关于PipeTransmissionMode.Message:如何.NET命名管道的消息之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆