[][src]Function tcp_test::channel

pub fn channel() -> (TcpStream, TcpStream)

Returns two TCP streams pointing at each other.

The internal TCP listener is bound to


use tcp_test::channel;
use std::io::{Read, Write};

fn test() {
    let data = b"Hello world!";
    let (mut local, mut remote) = channel();

    let local_addr = local.local_addr().unwrap();
    let peer_addr = remote.peer_addr().unwrap();

    assert_eq!(local_addr, peer_addr);
    assert_eq!(local.peer_addr().unwrap(), "".parse().unwrap()); // default address


    let mut buf = [0; 12];
    remote.read_exact(&mut buf).unwrap();

    assert_eq!(&buf, data);

Also see the module level example.