pub async fn tcp_connect(
    cfg: Cfg,
    target: Vec<String>,
    default_port: u16
) -> Result<Stream>
Expand description

Builds a connection consisting of aggregated TCP links to the target.

cfg is the configuration and in most cases Cfg::default() should be used.

target specifies a set of IP addresses or hostnames of the target host. If a hostname resolves to multiple IP addresses this is taken into account automatically. If an entry in target specifies no port number, default_port is used.

Links are established automatically from all available local network interfaces to all IP addresses of the target. If a link fails, it is reconnected automatically.

Returns the connection stream.

Example

This example connects to the host server on port 5900.

Multiple links will be used if the local machine has multiple interfaces that can all connect to server, or server has multiple interfaces that are registered with their IP addresses in DNS.

use aggligator::cfg::Cfg;
use aggligator_util::net::tcp_connect;

#[tokio::main]
async fn main() -> std::io::Result<()> {
    let stream = tcp_connect(Cfg::default(), vec!["server".to_string()], 5900).await?;

    // use the connection

    Ok(())
}