pub async fn server_start<W: AsyncWrite + Unpin>(
stream: &mut W,
identifier: &str,
version: &str,
last: Result<((u16, String), RsaPublicKey), StarterError>,
) -> Result<(Cipher, u16, String), StarterError>
Available on crate feature
compress_encryption
only.Expand description
Make sure the server side is ready to use in tcp-handler compress_encrypt protocol.
Must be used in conjunction with server_init
.
§Runtime
Due to call block_in_place
internally,
this function cannot be called in a current_thread
runtime.
§Arguments
stream
- The tcp stream orWriteHalf
.identifier
- The returned application identifier. (Should be same with the para inserver_init
.)version
- The returned recommended application version. (Should be passed the prediction inserver_init
.)last
- The return value ofserver_init
.
§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(())
}