pub fn channel(protocol: Protocol) -> Result<(Link, Link), Error>
Expand description
Create a full-duplex WSTP communication channel with two Link
endpoints.
This function is a convenient alternative to manually using
Link::listen()
and Link::connect()
to create a channel.
Example
Construct a channel, and send data in both directions:
use wstp::Protocol;
let (mut a, mut b) = wstp::channel(Protocol::SharedMemory).unwrap();
a.put_str("from a to b").unwrap();
a.flush().unwrap();
b.put_str("from b to a").unwrap();
b.flush().unwrap();
assert_eq!(a.get_string().unwrap(), "from b to a");
assert_eq!(b.get_string().unwrap(), "from a to b");