Function client_init

Source
pub async fn client_init<W: AsyncWrite + Unpin>(
    stream: &mut W,
    identifier: &str,
    version: &str,
) -> Result<RsaPrivateKey, StarterError>
Available on crate feature encryption only.
Expand description

Init the client side in tcp-handler encrypt protocol.

Must be used in conjunction with client_start.

§Runtime

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

§Arguments

  • stream - The tcp stream or WriteHalf.
  • identifier - The identifier of your application.
  • version - Current version of your application.

§Example

use anyhow::Result;
use tcp_handler::protocols::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(())
}