7 releases
0.1.5 | Sep 13, 2023 |
---|---|
0.1.4 | Jan 2, 2023 |
0.1.3 | Dec 23, 2022 |
0.1.1 | Nov 29, 2022 |
0.0.0 | Nov 11, 2022 |
27KB
489 lines
mezzenger-udp
UDP transport for mezzenger.
https://crates.io/crates/mezzenger-udp
usage
Add dependencies to Cargo.toml
:
[dependencies]
# ...
serde = { version = "1", features = ["derive"] }
kodec = { version = "0.1.0", features = ["binary"] } # or json or different one from another crate...
mezzenger = "0.1.3"
mezzenger-udp = "0.1.2"
Now, in code:
let udp_socket = UdpSocket::bind("127.0.0.1:8080").await?;
udp_socket.connect(remote_address).await?;
use kodec::binary::Codec;
let mut transport: Transport<_, Codec, i32, String> =
Transport::new(udp_socket, Codec::default());
use mezzenger::Receive;
let integer = transport.receive().await?;
transport.send("Hello World!".to_string()).await?;
see also
lib.rs
:
Transport for communication over tokio UDP implementation.
NOTE: This transport inherits UDP properties:
- it is unreliable - messages are not guaranteed to reach destination,
- it is unordered - messages may arrive at destination out of order, also they may be duplicated (the same message may arrive at destination twice or more times).
- message size is limited to datagram size - sending may result in error if encoded message is too large.
See repository for more info.
Example
let udp_socket = UdpSocket::bind("127.0.0.1:8080").await?;
udp_socket.connect(remote_address).await?;
use kodec::binary::Codec;
let mut transport: Transport<_, Codec, i32, String> =
Transport::new(udp_socket, Codec::default());
use mezzenger::Receive;
let integer = transport.receive().await?;
transport.send("Hello World!".to_string()).await?;
Dependencies
~3–12MB
~126K SLoC