Function aggligator_util::net::tcp_connect
source · pub async fn tcp_connect(
target: impl IntoIterator<Item = String>,
default_port: u16
) -> Result<Stream>Available on crate feature
tcp only.Expand description
Builds a connection consisting of aggregated TCP links to the target.
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_util::net::tcp_connect;
#[tokio::main]
async fn main() -> std::io::Result<()> {
let stream = tcp_connect(["server".to_string()], 5900).await?;
// use the connection
Ok(())
}