Function aggligator_util::net::tcp_server
source · pub async fn tcp_server<F>(
cfg: Cfg,
addr: SocketAddr,
work_fn: impl Fn(Stream) -> F + Send + 'static
) -> Result<()>where
F: Future<Output = ()> + Send + 'static,Expand description
Runs a TCP server accepting connections of aggregated links.
cfg is the configuration and in most cases Cfg::default() should be used.
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::cfg::Cfg;
use aggligator_util::net::tcp_server;
#[tokio::main]
async fn main() -> std::io::Result<()> {
tcp_server(
Cfg::default(),
SocketAddr::new(Ipv6Addr::UNSPECIFIED.into(), 5900),
|stream| async move {
// use the incoming connection
}
).await?;
Ok(())
}