5 releases

0.0.11 Jan 26, 2024
0.0.10 Dec 7, 2023
0.0.9 Jul 9, 2023
0.0.3 Jul 15, 2022
0.0.0-alpha.3 Nov 30, 2019

#565 in Network programming

Download history 91/week @ 2023-12-21 91/week @ 2023-12-28 205/week @ 2024-01-04 398/week @ 2024-01-11 328/week @ 2024-01-18 271/week @ 2024-01-25 241/week @ 2024-02-01 547/week @ 2024-02-08 221/week @ 2024-02-15 380/week @ 2024-02-22 496/week @ 2024-02-29 416/week @ 2024-03-07 211/week @ 2024-03-14 1031/week @ 2024-03-21 1180/week @ 2024-03-28 1222/week @ 2024-04-04

3,734 downloads per month
Used in 5 crates

MIT license

228 lines



udp-stream is a Rust library that provides a simple API for handling streaming data over the User Datagram Protocol (UDP), similar to TcpStream. It abstracts the complexities of working with UDP, such as handling packet fragmentation, reassembly, and flow control, making it easy for developers to send and receive continuous streams of data over UDP sockets especially when using DTLS protocol.


  • Stream-based: udp-stream provides an abstraction layer for handling UDP packets as a continuous stream of data, using a similar function signature as TcpStream in the tokio library. This allows developers familiar with tokio to leverage their existing knowledge to work with UDP in a similar manner.

  • Lightweight: udp-stream has a small footprint and only depends on the tokio and bytes libraries, making it lightweight and easy to integrate into your existing projects.


To use udp-stream in your Rust project, simply add it as a dependency in your Cargo.toml file:


udp-stream = "0.0.10"

Then, you can import and use the library in your Rust code:


use std::{net::SocketAddr, str::FromStr};

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

use udp_stream::UdpStream;

async fn main() -> Result<(), Box<dyn Error>> {
    let mut stream = UdpStream::connect(SocketAddr::from_str("")?).await?;
    println!("Ready to Connected to {}", &stream.peer_addr()?);
    let mut buffer = String::new();
    loop {
        std::io::stdin().read_line(&mut buffer)?;
        let mut buf = vec![0u8; 1024];
        let n = stream.read(&mut buf).await?;
        print!("-> {}", String::from_utf8_lossy(&buf[..n]));

For more details on how to use udp-stream, including configuration options, using for DTLS, and advanced usage, please refer to the examples.


Contributions to udp-stream are welcome! If you would like to contribute to the library, please follow the standard Rust community guidelines for contributing, including opening issues, submitting pull requests, and providing feedback.


udp-stream is licensed under the MIT License, which allows for free use, modification, and distribution, subject to the terms and conditions outlined in the license.

We hope that udp-stream is useful for your projects! If you have any questions or need further assistance, please don't hesitate to contact us or open an issue in the repository.


~130K SLoC