Module strymon_communication::transport [] [src]

Asynchronous point-to-point message channels.

The implementation is a thin wrapper around TCP sockets and thus follows the same semantics: One peer needs to act as a Listener, accepting new incoming connections.

A connection conists of a pair of queue handles:

  1. A non-blocking Sender which enqueues MessageBuf objects to be eventually sent over the network.
  2. A non-blocking Receiver receiving the messages in the same order they were sent.

Examples

extern crate futures;
extern crate strymon_communication;

use std::io;
use std::thread;
use futures::stream::Stream;
use strymon_communication::Network;
use strymon_communication::message::MessageBuf;

fn run_example() -> io::Result<String> {
    let network = Network::new(String::from("localhost"))?;
    let listener = network.listen(None)?;
    let (_, port) = listener.external_addr();
    thread::spawn(move || {
        let mut blocking = listener.wait();
        while let Some(Ok((tx, _rx))) = blocking.next() {
            tx.send(MessageBuf::new("Hello").unwrap());
        }
    });

    let (_tx, rx) = network.connect(("localhost", port))?;
    let mut msg = rx.wait().next().unwrap()?;
    msg.pop::<String>()
}

fn main() {
    assert_eq!("Hello", run_example().expect("I/O failure"));
}

Structs

Listener

A queue handle accepting incoming connections.

Receiver

A queue handle for receiving messages on the channel.

Sender

A queue handle to send messages on the channel.