udp转发器
````rust
use net_relay::RelayExt;
use udp_pool::net_pool::{Address, debug, Pool};
#[tokio::main]
async fn main() {
init_log();
if let Err(_e) = run().await {
debug!("run error:{:?}", _e);
}
}
async fn run() -> Result<(), net_relay::Error> {
let mut relay = udp_relay::Relay::build(|b| {
let pool = udp_pool::Pool::default();
pool.add_backend(None, Address::from("127.0.0.1:3002"));
b.bind("0.0.0.0:3001")
.relay_fn(udp_relay::default_relay_fn)
.pool(pool)
})
.map(|r| Box::new(r) as Box<dyn net_relay::Relay>)?;
loop {
tokio::select! {
res = relay.run() => {
return res;
}
};
}
}
fn init_log() {
#[cfg(feature = "tracing")]
{
tracing_subscriber::fmt()
.with_max_level(tracing::Level::TRACE)
.init();
}
}