rmw-stun

Crates.iormw-stun
lib.rsrmw-stun
version0.0.3
sourcesrc
created_at2021-11-17 08:33:06.690483
updated_at2021-11-18 09:08:07.697394
descriptionget external ip port via stun server
homepage
repositoryhttps://github.com/rmw-lib/node/tree/master/stun
max_upload_size
id483210
size32,357
gcxfd (gcxfd)

documentation

README

rmw-stun

get external ip port via stun server

use example

use async_std::net::UdpSocket;
use rmw_stun::external_addr;
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use std::time::{Instant};

#[async_std::main]
async fn main() {
  let udp = UdpSocket::bind(SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 0))
    .await
    .unwrap();
  //let server = "not.exist.stun:3478";
  let server = "stun.cablenet-as.net:3478";
  let timeout = 3;
  let start = Instant::now();
  let addr = external_addr(&udp, server, timeout).await;
  let duration = start.elapsed();

  println!("external addr {:?} cost {:?}", addr, duration);
}

output as below

external addr Ok(54.177.127.37:40143) cost 402.976326ms

关于

本项目隶属于人民网络(rmw.link) 代码计划。

人民网络

Commit count: 0

cargo fmt