libutp-rs2

Crates.iolibutp-rs2
lib.rslibutp-rs2
version0.1.4
created_at2025-02-17 13:55:57.76583+00
updated_at2025-08-02 10:18:44.998592+00
descriptionRust bindings for libutp
homepage
repositoryhttps://github.com/ikatson/libutp-rs2
max_upload_size
id1558937
size55,746
Igor Katson (ikatson)

documentation

https://docs.rs/libutp-rs2

README

Async Tokio library for uTP (uTorrent transport protocol) using C-based libutp under the hood.

Working and tested alternative to libutp-rs

Docs

Example


use libutp_rs2::UtpUdpContext;
use tokio::io::{AsyncReadExt, AsyncWriteExt};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    // Server
    let server_addr = "127.0.0.1:8001".parse()?;
    let listener = tokio::spawn(async move {
        let mut buf = String::new();
        UtpUdpContext::new_udp(server_addr)
            .await?
            .accept()
            .await?
            .read_to_string(&mut buf)
            .await?;
        Ok::<_, anyhow::Error>(buf)
    });

    // Client
    tokio::spawn(async move {
        UtpUdpContext::new_udp("127.0.0.1:8002".parse()?)
            .await?
            .connect(server_addr)
            .await?
            .write_all(b"hello")
            .await?;
        Ok::<_, anyhow::Error>(())
    });

    println!("{}", listener.await.unwrap().unwrap());

    Ok(())
}
Commit count: 30

cargo fmt