#multiplexing #muxing #async-io #tokio #smux

tokio_smux

Smux protocol in Rust. Provide multiplexing for reliable streams.

3 unstable releases

0.2.0 Jan 20, 2024
0.1.1 Jan 13, 2024
0.1.0 Jan 13, 2024

#1596 in Network programming

Download history 7/week @ 2024-01-09 5/week @ 2024-01-16 5/week @ 2024-02-20 27/week @ 2024-02-27 11/week @ 2024-03-12 3/week @ 2024-03-26 41/week @ 2024-04-02 69/week @ 2024-04-09

113 downloads per month

MIT license

55KB
1.5K SLoC

tokio_smux

Build And Test crates.io

Tokio_smux is an implementation of smux in Rust, which is a stream multiplexing library in Golang.

Tokio_smux can work with tokio TcpStream and KcpStream. It can also be used with any streams that implement tokio's AsyncRead and AsyncWrite traits.

Docs

https://docs.rs/tokio_smux

Usage Example

See examples

Smux Protocol Implementation

The smux protocl version 2 is not yet supported.

Why doesn't Stream of tokio_smux impl AsyncRead and AysncWrite itself?

Becuase the smux protocol uses frames, means all user data transfered is wrapped in frames of fixed lengths. Similar to the websocket protocol.

Using frames has its benifits: it maintains message boundaries. For example, you can send many one byte data messages to the remote, and receive them one by one in the remote.

It's still feasible to wrap the current APIs of Stream to provide AsyncRead and AsyncWrite. However, this approach introduces additional overhead and loses message boundaries.

Dependencies

~4–13MB
~140K SLoC