Can somebody clarify the meaning of PipeTransmissionMode.Message
in .NET?
How does .NET distinguish one message passed through the pipe from another?
BinaryFormatter
and then pass it through the pipe as a message? PipeTransmissionMode.Message
mode?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:
The .NET wrapping of this functionality, as surfaced in the System.IO.Pipes
namespace, follows the underlying native model fairly closely:
PipeStream.Write()
or
PipeStream.WriteByte()
- the data
written in each call is treated as a distinct
message;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 readAll 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.
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()
.