pub async fn server_init<R: AsyncRead + Unpin, P: FnOnce(&str) -> bool>(
stream: &mut R,
identifier: &str,
version: P,
) -> Result<(u16, String), StarterError>
Available on crate feature
compression
only.Expand description
Init the server side in tcp-handler compress protocol.
Must be used in conjunction with tcp_handler::compress::server_start
.
§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::{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;
server_start(&mut server, "test", "0", s_init).await?;
// Now the server is ready to use.
Ok(())
}