Last active
September 28, 2023 03:15
-
-
Save gold24park/a287047312ab5062d0bda24802119db7 to your computer and use it in GitHub Desktop.
rust udp echo server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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