Stream API for tokio-udp.

Overview

UDPflow

crates.io Released API docs

Stream API for tokio-udp.

TCP-like UDP stream

use tokio::net::UdpSocket;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use udpflow::{UdpListener, UdpStreamLocal, UdpStreamRemote};
async fn server() {
    let socket = UdpSocket::bind("127.0.0.1:5000").await.unwrap();
    let listener = UdpListener::new(socket);
    let mut buf = vec![0u8; 0x2000];
    // listener must be continuously polled to recv packets or accept new streams
    while let Ok((stream, addr)) = listener.accept(&mut buf).await {
        tokio::spawn(handle(stream));
    }
}
async fn handle(mut stream1: UdpStreamLocal) {
    let socket = UdpSocket::bind("127.0.0.1:0").await.unwrap();
    let mut stream2 = UdpStreamRemote::new(socket, "127.0.0.1:10000".parse().unwrap());
    let mut buf = vec![0u8; 256];
    stream1.read(&mut buf).await; stream2.write(&buf).await;
    stream2.read(&mut buf).await; stream1.write(&buf).await;
}

Send/Recv framed data

use tokio::net::TcpStream;
use udpflow::UotStream;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
async {
    let stream = TcpStream::connect("127.0.0.1:8080").await.unwrap();
    let mut stream = UotStream::new(stream);
    let mut buf = vec![0u8; 256];
    // read a frame
    let n = stream.read(&mut buf).await.unwrap();
    // write a frame
    stream.write_all(&buf[..n]).await;
};

UoT Specification

+------+----------+
| LEN  |   DATA   |
+------+----------+
|  2   | Variable |
+------+----------+

*LEN is a 16-bit unsigned integer in big endian byte order.

You might also like...
SOCKS5 implement library, with some useful utilities such as dns-query, socks5-server, dns2socks, udp-client, etc.

socks5-impl Fundamental abstractions and async read / write functions for SOCKS5 protocol and Relatively low-level asynchronized SOCKS5 server impleme

General-purpose asynchronous socket stream.

async-socket This crate implements a general-purpose asynchronous socket. The Socket implements AsyncRead, AsyncWrite, Stream and Clone traits and thu

SpringQL: Open-source stream processor for IoT devices and in-vehicle computers

What is SpringQL? SpringQL is an open-source stream processor specialized in memory efficiency. It is supposed to run on embedded systems like IoT dev

A simple web server(and library) to display server stats over HTTP and Websockets/SSE or stream it to other systems.

x-server-stats A simple web server(and library) to display server stats over HTTP and Websockets/SSE or stream it to other systems. x-server(in x-serv

Crate extending futures stream combinators, that is adding precise rate limiter
Crate extending futures stream combinators, that is adding precise rate limiter

stream-rate-limiter Stream combinator .rate_limiter(opt: RateLimitOptions) Provides way to limit stream element rate with constant intervals. It adds

Stream & Download Cartoons & Animes

eren Stream & Download Cartoons & Animes Install Linux/Mac First of all install rust then git clone 'https://github.com/Based-Programmer/eren' && \ cd

Rust Tokio 异步多客户端网络框架 高并发 插件化

Rust实现的异步多客户端网络框架,基于tokio和mlua,可自定义通讯协议 插件化采用lua。应用场景im,game server,bot等.

A super minimal wrapper around unix sockets for IPC on top of tokio.

tokio-unix-ipc This crate implements a minimal abstraction over UNIX domain sockets for the purpose of IPC on top of tokio.

A proxy implement with http / socks5 in-bound and vmess out-bound, written in Rust and tokio.rs

tokio-vmess an Asynchronous proxy implement with http / socks5 in-bound and vmess out-bound, written in Rust and tokio Run example first, Fill out the

Owner
zephyr
amateur player, code for fun
zephyr
A small holepunching implementation written in Rust (UDP)

rust-udp-holepunch A small holepunching implementation written in Rust (UDP) Prerequisites Your rendezvous server must lay in a network which doesn't

Amit Katz 8 Dec 26, 2022
Fast User-Space TCP/UDP Stack

Catnip Catnip is a TCP/IP stack that focuses on being an embeddable, low-latency solution for user-space networking. Building and Running 1. Clone Thi

Demikernel 79 Sep 9, 2022
Test the interception/filter of UDP 53 of your local networks or hotspots.

udp53_lookup Test the interception/filter of UDP 53 of your local networks or hotspots. Inspired by BennyThink/UDP53-Filter-Type . What's the purpose?

null 1 Dec 6, 2021
Tachyon is a performant and highly parallel reliable udp library that uses a nack based model

Tachyon Tachyon is a performant and highly parallel reliable udp library that uses a nack based model. Strongly reliable Reliable fragmentation Ordere

Chris Ochs 47 Oct 15, 2022
UDP proxy with Proxy Protocol and mmproxy support

udppp UDP proxy with Proxy Protocol and mmproxy support. Features Async Support Proxy Protocol V2 SOCKET preserve client IP addresses in L7 proxies(mm

b23r0 10 Dec 18, 2022
Aggressively reliable delivery layer. Above UDP. Nothing else.

Aggressively reliable delivery layer. Above UDP. Nothing else.

IchHabeKeineNamen 2 Jun 5, 2022
A transparent QUIC to SOCKSv5 proxy on Linux, UDP/QUIC verison of moproxy.

quproxy A transparent QUIC to SOCKSv5 proxy on Linux, UDP/QUIC verison of moproxy. ?? WORKING IN PROGRESS ?? Features: Transparent forward QUIC to ups

Shell Chen 4 Dec 15, 2022
Quick Peer-To-Peer UDP file transfer

qft QFT is a small application for Quick (and really reliable) Peer-To-Peer UDP file transfer. If a friend sent you here... ...look at the "Releases"

Daniel H. 99 Jan 7, 2023
Rust implementation of TCP + UDP Proxy Protocol (aka. MMProxy)

mmproxy-rs A Rust implementation of MMProxy! ?? Rationale Many previous implementations only support PROXY Protocol for either TCP or UDP, whereas thi

Saikō Technology 3 Dec 29, 2022
🦀 A bit more reliable UDP written in Rust

AckUDP [EXPERIMENTAL] A bit more reliable version of UDP written in Rust. How to use? use std::{io, thread, time::Duration}; use ack_udp::AckUdp; #[

Ivan Davydov 3 May 9, 2023