tcplane

Official Documentation
Api Docs
tcplane is a lightweight and high-performance Rust TCP server library designed to simplify network service development. It supports TCP communication, data stream management, and connection handling, focusing on providing efficient low-level network connections and data transmission capabilities, making it ideal for building modern network services.
Installation
To use this crate, you can run cmd:
cargo add tcplane
Use
use tcplane::*;
async fn test_middleware(arc_lock_controller_data: ArcRwLockControllerData) {
let mut controller_data: RwLockWriteControllerData =
arc_lock_controller_data.get_write_lock().await;
{
let request: &mut Request = controller_data.get_mut_request();
let mut new_request: Request = request.clone();
let ext: Request = "hello world".as_bytes().to_vec();
new_request.extend(ext);
*request = new_request;
}
let request: Request = controller_data.get_request().clone();
let host: String = arc_lock_controller_data.get_socket_addr().await.unwrap();
controller_data.get_log().debug(
format!(
"Request host => {}\n{:#?}\n",
host,
String::from_utf8_lossy(&request),
),
log_debug_format_handler,
);
}
async fn test_func(arc_lock_controller_data: ArcRwLockControllerData) {
let res: ResponseData = arc_lock_controller_data.send("tcplane").await.unwrap();
arc_lock_controller_data.get_controller_data().await.get_log().debug(
format!("Response => {:?}\n", String::from_utf8_lossy(&res)),
log_debug_format_handler,
);
}
async fn run_server() {
let mut server: Server = Server::new();
server.host("0.0.0.0").await;
server.port(60000).await;
server.log_dir("./logs").await;
server.log_size(100_024_000).await;
server.buffer(100_024_000).await;
server.log_interval_millis(360).await;
server.middleware(test_middleware).await;
server.func(test_func).await;
let test_string: String = "test".to_owned();
server
.func(async_func!(test_string, |data| {
println_success!(&test_string);
println_success!(&format!("{:?}", data));
}))
.await;
server.listen().await;
}
License
This project is licensed under the MIT License. See the LICENSE file for details.
Contributing
Contributions are welcome! Please open an issue or submit a pull request.
Contact
For any inquiries, please reach out to the author at ltpp-universe root@ltpp.vip.