[][src]Function tcp_test::channel_on

pub fn channel_on(address: impl ToSocketAddrs) -> (TcpStream, TcpStream)

Returns two TCP streams pointing at each other.

The internal TCP listener is bound to address. Only one listener is used throughout the entire program, so the address should match in all calls to this function, otherwise it is not specified which address is finally used.

Example

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

let data = b"Hello world!";
let (mut local, mut remote) = channel_on("127.0.0.1:31398");

let local_addr = remote.local_addr().unwrap();
let peer_addr = local.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);