channels 0.3.0

Bidirectional channel-like communication over generic Read/Write streams
Documentation

channels-rs

license-badge version-badge downloads-badge

channels is a crate that allows for easy and fast communication between processes, threads and systems.

Anything you might need can be found over at the documentation @ docs.rs

Examples

Simple echo server:

use std::io;
use std::net::TcpListener;

use channels;

	fn main() -> io::Result<()> {
		let listener = TcpListener::bind("0.0.0.0:1337")?;

		loop {
			let (stream, _) = listener.accept()?;
			let (mut tx, mut rx) = channels::channel::<i32, _>(stream);

			let client_data = rx.recv()?;

			println!("Client sent: {}", client_data);

			tx.send(client_data)?;
		}

 	Ok(())
}

Simple echo client:

use std::io;
use std::net::TcpStream;

fn main() -> io::Result<()> {
		let stream = TcpStream::connect("127.0.0.1:1337")?;
		let (mut tx, mut rx) = channels::channel::<i32, _>(stream);

		tx.send(1337_i32)?;

		let received_data = rx.recv()?;

		assert_eq!(received_data, 1337_i32);

 	Ok(())
}