udp

Crates.ioudp
lib.rsudp
version2.0.0
created_at2025-03-01 08:38:26.843174+00
updated_at2025-08-15 14:33:50.573813+00
descriptionA lightweight and efficient Rust library for building UDP servers with request-response handling.
homepage
repositoryhttps://github.com/crates-dev/udp.git
max_upload_size
id1573593
size42,850
尤雨东 (eastspire)

documentation

README

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: 1").await.unwrap();
}

fn error_handle(error: String) {
    eprintln!("{}", error);
    let _ = std::io::Write::flush(&mut std::io::stderr());
}

#[tokio::main]
async fn main() {
    let mut server: Server = Server::new().await;
    server.host("0.0.0.0").await;
    server.port(60000).await;
    server.buffer(100_024_000).await;
    server.error_handle(error_handle).await;
    server.func(test_func).await;
    server
        .func(|ctx: Context| async move {
            ctx.send("udp: 2").await.unwrap();
        })
        .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 root@ltpp.vip.

Commit count: 0

cargo fmt