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

udp

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

50 releases (24 breaking)

Uses new Rust 2024

new 0.24.0 May 7, 2025
0.22.1 Apr 19, 2025
0.17.0 Mar 30, 2025

#1688 in Network programming

Download history 1682/week @ 2025-03-01 335/week @ 2025-03-08 496/week @ 2025-03-15 1076/week @ 2025-03-22 737/week @ 2025-03-29 346/week @ 2025-04-05 512/week @ 2025-04-12 218/week @ 2025-04-19 22/week @ 2025-04-26 223/week @ 2025-05-03

987 downloads per month

MIT license

28KB
727 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(ctx: Context) {
    ctx.send("udp").await.unwrap();
    let response: Response = ctx.get_response().await;
    let response_data: &ResponseData = response.get_response_data();
    ctx.log_debug(
        &format!(
            "Response => {:?}\n",
            String::from_utf8_lossy(&response_data)
        ),
        log_handler,
    )
    .await;
}

#[tokio::main]
async fn main() {
    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.func(test_func).await;
    let test_string: String = "test".to_owned();
    server
        .func(future_fn!(test_string, |data| {
            println_success!(&test_string);
            println_success!(String::from_utf8_lossy(&data.get_request().await));
        }))
        .await;
    server.run().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

~6–14MB
~152K SLoC