Giter Site home page Giter Site logo

kouweizhong / nerdbank.fullduplexstream Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dotnet/nerdbank.streams

0.0 1.0 0.0 35 KB

A full duplex .NET Stream implementation that allows for two in-proc components to exchange messages over Streams.

License: MIT License

C# 100.00%

nerdbank.fullduplexstream's Introduction

Full duplex .NET Streams

Build status NuGet package

Installation

Consume this project by installing the Nerdbank.FullDuplexStream NuGet package.

The code to set up a full duplex stream is trivial:

Tuple<Stream, Stream> tuple = FullDuplexStream.CreateStreams();
Task party1Simulation = Party1Async(tuple.Item1);
Task party2Simulation = Party2Async(tuple.Item2);

In the above code, we create a pair of streams. Each goes to one of two parties. They can each read and write to their stream to communicate with the other party, who uses their own stream. The two streams in the returned Tuple are interconnected.

What and why of full duplex streams

.NET streams are great for accessing files, or communicating with a remote party. They can also be useful for bidirectional (i.e. full duplex) communication between two parties. .NET named pipes demonstrate such a use of .NET Stream. When using Stream in this way between two parties, each party gets one unique instance of Stream. Party 1 can write to their Stream to send messages to Party 2 and read from that same stream to receive messages from Party 2. Party 2 can likewise read and write to their stream to exchange messages with Party 1. Although each party has their own unique instance of Stream, the two streams are connected such that writing to one allows that data to be read from the other.

Uses of full duplex Streams

  • Testing a networking protocol by simulating both ends of communication.
  • Named pipe-like communication between two in-proc components.

FAQ

Why not just use MemoryStream?

A single MemoryStream has a Position property, which advances whenever the Stream is read from or written to. So if one party writes to the stream, the Position is advanced to the end of the written data, such that if the other party tried to read from the stream, they would not see the data previously written by the other party.

Why not just use named pipes?

Named pipes carry the overhead of operating system handles and are not portable. The concept of full duplex streaming is simple and can be implemented in a portable way.

nerdbank.fullduplexstream's People

Contributors

aarnott avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.