简体   繁体   中英

TPL Dataflow with TCP NetworkStream

Can TPL Dataflow be used for processing a TCP byte stream? I'm fairly new to this topic and am looking for the best way to process a TCP byte stream.

To be more specific: I'm using a protocol (HSMS) on top of TCP/IP which specifies messages with 4 length bytes and a message structure. I'm writing a library and have a consumer who receives the decoded messages. What I need to do in my library is:

  • read the bytes from the Socket and buffer them
  • as soon as I have the length bytes and the message itself I need to transform/decode it.
  • then I'll pass the message to the consumer of the library

Usually I have one producer and one consumer. And the IO operations are asynchronous.

I started doing it all manually but realized that it's quite complex and tedious, especially with thread safety. So I stumbled upon TPL dataflow and am curious if it's worth considering for this case. My main concern is that I have only one producer (Socket) and one consumer and wonder if it's overkill.

I also found System.IO.Pipelines but also there is not much information for my use case.

I understand it's an old post.

Yes TPL dataflow is well suitable for this task, but for such a simple processing scenario, you might use system.io.pipeline within RX. It's quite direct once you made the effort to dig into io.pipeline and RX.

Then, Dataflow will come after that, connected to your IObservable<T> , as streaming pipeline you can use to elaborate complex data processing.

Regards

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM