udp_reverse.rs 423 B

12345678910111213141516
  1. use wasmedge_wasi_socket::UdpSocket;
  2. fn main() -> std::io::Result<()> {
  3. let port = std::env::var("PORT").unwrap_or("3000".to_string());
  4. let socket = UdpSocket::bind(format!("127.0.0.1:{}", port))?;
  5. let mut buf = [0; 128];
  6. let (size, addr) = socket.recv_from(&mut buf)?;
  7. println!("recv from {}", addr);
  8. let buf = &mut buf[..size];
  9. buf.reverse();
  10. socket.send_to(buf, &addr)?;
  11. Ok(())
  12. }