Skip to content

Instantly share code, notes, and snippets.

@gold24park
Last active September 28, 2023 03:15
Show Gist options
  • Save gold24park/a287047312ab5062d0bda24802119db7 to your computer and use it in GitHub Desktop.
Save gold24park/a287047312ab5062d0bda24802119db7 to your computer and use it in GitHub Desktop.
rust udp echo server
use std::{error::Error, net::UdpSocket, str::from_utf8};
fn main() -> std::io::Result<()> {
let socket = UdpSocket::bind("[::]:2000")?;
let mut buf = [0; 65507];
loop {
let (read, from) = socket.recv_from(&mut buf)?;
println!("Received {} bytes from {}", read, from);
socket.send_to(&buf[..read], from)?;
}
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment