demo

use tokio::net::TcpStream;
 
use std::error::Error;
 
#[tokio::main]
pub async fn main() -> Result<(), Box<dyn Error>> {
    // Open a TCP stream to the socket address.
    //
    // Note that this is the Tokio TcpStream, which is fully async.
    let mut stream = TcpStream::connect("127.0.0.1:6142").await?;
    println!("created stream");
 
    Ok(())
}

internals

part 1: Get Socket Address

part 2: connect to an address