Trying to understand IDuplexPipe

485 Views Asked by At

I'm working on a web socket wrapper around Binance's web socket stream. System.IO.Pipelines looks interesting to me because of the problems it solves.

I'm most likely going to take one of the following implementations:

I'm unable to understand what the difference between IDuplexPipe and Pipe is.

The IDuplexPipe is a contract for types that support both reading and writing. For example, a network connection would be represented by an IDuplexPipe.

Since the web socket wrapper I'm working on is related to Binance's web socket stream, I assume I need the IDuplexPipe?

SignalR uses IDuplexPipe and DotNet.Interactive.PowerShell uses onl the Pipe class. Can you enlighten of what the difference between these two is with real life example, because I don't really understand what Microsoft's documentation states.

1

There are 1 best solutions below

0
On BEST ANSWER

IDuplexPipe documentation:

Defines a class that provides a duplex pipe from which data can be read from and written to.

An IDuplexPipe is an interface that represent something you can Read from, using the PipeReader, and Write to, using the PipeWriter.
The IO.Pipelines Pipe is simply a buffer.

It's explained in the docs you linked: https://learn.microsoft.com/en-us/dotnet/standard/io/pipelines#pipe

The Pipe class can be used to create a PipeWriter/PipeReader pair. All data written into the PipeWriter is available in the PipeReader: The PipeWriter write the data into the buffer, and the PipeReader read from it.