pub async fn tcp_server<F>(
    addr: SocketAddr,
    work_fn: impl Fn(Stream) -> F + Send + 'static
) -> Result<()>where
    F: Future<Output = ()> + Send + 'static,
Available on crate feature tcp only.
Expand description

Runs a TCP server accepting connections of aggregated links.

The TCP server listens on addr and accepts connections of aggregated TCP links. For each new connection the work function work_fn is spawned onto a new Tokio task.

Example

This example listens on all interfaces on port 5900.

If the server has multiple interfaces, all IP addresses should be registered in DNS so that clients can discover them and establish multiple links.

use std::net::{Ipv6Addr, SocketAddr};
use aggligator_util::net::tcp_server;

#[tokio::main]
async fn main() -> std::io::Result<()> {
    tcp_server(
        SocketAddr::new(Ipv6Addr::UNSPECIFIED.into(), 5900),
        |stream| async move {
            // use the incoming connection
        }
    ).await?;

    Ok(())
}