channels-rs
channels is a crate that allows for easy and fast communication between processes, threads and systems.
Sender/Receiver types to be used with any type that implements [std::io::Read] and [std::io::Write].
This crate is similar to [std::sync::mpsc] in terms of the API, and most of the documentation
for that module carries over to this crate.
Don't think of these channels as a replacement for [std::sync::mpsc], but as another implementation that works over many different transports.
These channels are meant to be used in combination with network sockets, local sockets, pipes, etc. And can be chained with other adapter types to create complex and structured packets.
The differences are:
- Channels will block, unless the underlying stream is set as non-blocking.
- The amount of messages that can be queued up before reading is dependent on the underlying stream.
Features
statistics: Capture statistic data like: total bytes sent/received, timestamp of last packet, etc
Default features
serde: Adds support for sending/receiving any type withserdeandbincode
Examples
For more complete and complex examples see: examples/
Simple echo server
use io;
use TcpListener;
let listener = bind.unwrap;
loop
Simple echo client
use io;
use TcpStream;
let stream = connect.unwrap;
let = ;
tx.send.unwrap;
let received_data = rx.recv.unwrap;
assert_eq!;
Multi-threaded echo server
use TcpListener;
let listener = bind.unwrap;
loop
Send/Recv with 2 threads
use io;
use TcpStream;
let stream = connect.unwrap;
let = ;
// Receiving thread
let recv_thread = spawn;
// Sending thread
let send_thread = spawn;
recv_thread.join.unwrap;
send_thread.join.unwrap;