PipeTransmissionMode.Message: How do .NET named pipes distinguish between messages?

后端 未结 2 1348
感情败类
感情败类 2020-12-08 18:31

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

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

  • C
2条回答
  •  误落风尘
    2020-12-08 19:18

    Took me a while to find the little important detail that you need to create both the server and client in PipeDirection.InOut mode:

    It may be odd, but for some reason, a NamedPipeServerStream must be created with a PipeDirection parameter of InOut in order for PipeTransmissionMode.Message to work. Not only is this not directly documented, but the way the error is reported is completely counter-intuitive, and appears to have nothing to do with the pipe's TransmissionMode.

    Otherwise you'll get the exception:

    Attempting to connect to pipe...System.UnauthorizedAccessException:

    Access to the path is denied.

       at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
       at System.IO.Pipes.PipeStream.WinIOError(Int32 errorCode)
       at System.IO.Pipes.PipeStream.set_ReadMode(PipeTransmissionMode value)
    

提交回复
热议问题