[][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 127.0.0.1:31398.

Example

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

#[test]
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(), "127.0.0.1:31398".parse().unwrap()); // default address

    local.write_all(data).unwrap();

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

    assert_eq!(&buf, data);
}

Also see the module level example.