Function client_start

Source
pub async fn client_start<R: AsyncRead + Unpin>(
    stream: &mut R,
    last: Result<RsaPrivateKey, StarterError>,
) -> Result<Cipher, StarterError>
Available on crate feature compress_encryption only.
Expand description

Make sure the client side is ready to use in tcp-handler compress_encrypt protocol.

Must be used in conjunction with client_init.

§Runtime

Due to call block_in_place internally, this function cannot be called in a current_thread runtime.

§Arguments

  • stream - The tcp stream or ReadHalf.
  • last - The return value of client_init.

§Example

use anyhow::Result;
use tcp_handler::protocols::compress_encrypt::{client_init, client_start};
use tokio::net::TcpStream;

#[tokio::main]
async fn main() -> Result<()> {
    let mut client = TcpStream::connect("localhost:25564").await?;
    let c_init = client_init(&mut client, "test", "0").await;
    let cipher = client_start(&mut client, c_init).await?;
    // Now the client is ready to use.
    Ok(())
}