Module madsim::net[][src]

Expand description

Asynchronous network endpoint and a controlled network simulator.

Examples

use madsim::{Runtime, net::NetLocalHandle};

let runtime = Runtime::new();
let addr1 = "0.0.0.1:1".parse().unwrap();
let addr2 = "0.0.0.2:1".parse().unwrap();
let host1 = runtime.local_handle(addr1);
let host2 = runtime.local_handle(addr2);

host1
    .spawn(async move {
        let net = NetLocalHandle::current();
        net.send_to(addr2, 1, &[1]).await.unwrap();
    })
    .detach();

let f = host2.spawn(async move {
    let net = NetLocalHandle::current();
    let mut buf = vec![0; 0x10];
    let (len, from) = net.recv_from(1, &mut buf).await.unwrap();
    assert_eq!(from, addr1);
    assert_eq!(&buf[..len], &[1]);
});

runtime.block_on(f);

Structs

Network configurations.

Network handle to the runtime.

Local host network handle to the runtime.

Network statistics.

Traits

A message that can be sent over the network.