A Rust library for implementing STUN server and client asynchronously.
The STUN protocol is defined in RFC 5389.
Add following lines to your Cargo.toml
:
toml
[dependencies]
rustun = "0.1"
A client-side example that issues a Binding request:
```rust extern crate fibers; extern crate rustun;
use fibers::{Executor, InPlaceExecutor, Spawn}; use rustun::{Method, Client}; use rustun::client::UdpClient; use rustun::rfc5389;
fn main() { let server_addr = "127.0.0.1:3478".parse().unwrap(); let mut executor = InPlaceExecutor::new().unwrap();
let mut client = UdpClient::new(&executor.handle(), server_addr);
let request = rfc5389::methods::Binding.request::<rfc5389::Attribute>();
let future = client.call(request);
let monitor = executor.spawn_monitor(future);
match executor.run_fiber(monitor).unwrap() {
Ok(v) => println!("OK: {:?}", v),
Err(e) => println!("ERROR: {}", e),
}
} ```
You can run example server and client which handle Binding
method as follows:
```bash
$ cargo run --example binding_srv
$ cargo run --example bindingcli -- 127.0.0.1 OK: Ok(SuccessResponse { method: Binding, transactionid: [246, 217, 191, 180, 118, 246, 250, 168, 86, 124, 126, 130], attributes: [XorMappedAddress(XorMappedAddress(V4(127.0.0.1:61991)))] }) ```