4 releases

0.2.1 Mar 1, 2022
0.2.0 Mar 1, 2022
0.1.2 Feb 6, 2022
0.1.0 Feb 6, 2022

#7 in #udp-client

32 downloads per month
Used in 2 crates

MIT/Apache

9KB
145 lines

Udp wrapper library

Async udp server

[dependencies]
udp_wrapper = "0.2"
tokio = { version = "1", features = ["full"] }

Then, on your main.rs:

async fn main() -> Result<(), Box<dyn Error>> {
    let server = UdpServerAsync::new("127.0.0.1:9001".to_string()).await?;
    let (_usize, address, data) = server.receive().await?;
    server.response(data, address);
}

Udp std server

[dependencies]
udp_wrapper = "0.2"
tokio = { version = "1", features = ["full"] }

Then, on your main.rs:

use udp_wrapper::UdpServer;
use std::error::Error;
async fn main() -> Result<(), Box<dyn Error>> {
    let server = UdpServer::new("127.0.0.1:9001".to_string())?;
    server.receive()
}

Udp client (client - server)

[dependencies]
udp_wrapper = "0.2"
tokio = { version = "1", features = ["full"] }

Then, on your main.rs:

async fn main() -> Result<(), Box<dyn Error>> {
    let client = UdpClient::new("127.0.0.1:9001".to_string())?;
    let response = client.send("Hello, I'm a client".to_string(), "127.0.0.1:9001".to_string())?;
}

Udp pusher (without response)

[dependencies]
udp_wrapper = "0.2"
tokio = { version = "1", features = ["full"] }

Then, on your main.rs:

use udp_wrapper::UdpPusher;
use std::error::Error;
async fn main() -> Result<(), Box<dyn Error>> {
    let pusher = UdpPusher::new("127.0.0.1:9001".to_string())?;
    pusher.send("Hello, I'm pusher".to_string(), "127.0.0.1:8081".to_string())?;
    Ok(())
}

License

This project is licensed under the MIT license.

Dependencies

~2.6–9MB
~74K SLoC