[][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 std::io::{Read, Write};

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);

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.