#udp-server #server #request-response #response #request #networking

udp

A lightweight and efficient Rust library for building UDP servers with request-response handling

21 releases (9 breaking)

new 0.9.1 Mar 7, 2025
0.8.2 Mar 3, 2025

#1752 in Network programming

Download history 1550/week @ 2025-02-28

1,550 downloads per month

MIT license

26KB
642 lines

udp

Official Documentation

Api Docs

A lightweight and efficient Rust library for building UDP servers with request-response handling.

Installation

To use this crate, you can run cmd:

cargo add udp

Use

use udp::*;

async fn test_func(controller_data: ControllerData) {
    let res: ResponseData = controller_data.send("udp").await.unwrap();
    controller_data
        .log_debug(
            format!("Response => {:?}\n", String::from_utf8_lossy(&res)),
            log_debug_format_handler,
        )
        .await;
}

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.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.

Dependencies

~7–14MB
~166K SLoC