Download Dataset_Construction/projects/libp2p/rust/examples/stream/README.md from SYSUSELab/RustRepoTrans: direct link, hf CLI and curl.
- Browser
- Download file 1.07 kB
-
https://huggingface.co/datasets/SYSUSELab/RustRepoTrans/resolve/main/Dataset_Construction/projects/libp2p/rust/examples/stream/README.md
- Command line
-
hf download hf://datasets/SYSUSELab/RustRepoTrans/Dataset_Construction/projects/libp2p/rust/examples/stream/README.md
-
curl -L -o README.md https://huggingface.co/datasets/SYSUSELab/RustRepoTrans/resolve/main/Dataset_Construction/projects/libp2p/rust/examples/stream/README.md
Description
This example shows the usage of the stream::Behaviour.
As a counter-part to the request_response::Behaviour, the stream::Behaviour allows users to write stream-oriented protocols whilst having minimal interaction with the Swarm.
In this showcase, we implement an echo protocol: All incoming data is echoed back to the dialer, until the stream is closed.
Usage
To run the example, follow these steps:
Start an instance of the example in one terminal:
cargo run --bin stream-exampleObserve printed listen address.
Start another instance in a new terminal, providing the listen address of the first one.
cargo run --bin stream-example -- <address>Both terminals should now continuously print messages.
Conclusion
The stream::Behaviour is an "escape-hatch" from the way typical rust-libp2p protocols are written.
It is suitable for several scenarios including:
- prototyping of new protocols
- experimentation with rust-libp2p
- integration in
async/await-heavy applications