pub async fn server_init<R: AsyncRead + Unpin, P: FnOnce(&str) -> bool>(
stream: &mut R,
identifier: &str,
version: P,
) -> Result<((u16, String), RsaPublicKey), StarterError>
Available on crate feature
compress_encryption
only.Expand description
Init the server side in tcp-handler compress_encrypt protocol.
Must be used in conjunction with server_start
.
§Runtime
Due to call block_in_place
internally,
this function cannot be called in a current_thread
runtime.
§Arguments
stream
- The tcp stream orReadHalf
.identifier
- The identifier of your application.version
- A prediction to determine whether the client version is allowed.
§Example
use anyhow::Result;
use tcp_handler::protocols::compress_encrypt::{server_init, server_start};
use tokio::net::TcpListener;
#[tokio::main]
async fn main() -> Result<()> {
let server = TcpListener::bind("localhost:25564").await?;
let (mut server, _) = server.accept().await?;
let s_init = server_init(&mut server, "test", |v| v == "0").await;
let (cipher, protocol_version, client_version) = server_start(&mut server, "test", "0", s_init).await?;
// Now the server is ready to use.
Ok(())
}