setup udp socket
This commit is contained in:
parent
115c51577f
commit
98b0173960
43
src/main.rs
43
src/main.rs
|
@ -1,28 +1,23 @@
|
|||
// Uncomment this block to pass the first stage
|
||||
// use std::net::UdpSocket;
|
||||
use std::net::UdpSocket;
|
||||
|
||||
fn main() {
|
||||
// You can use print statements as follows for debugging, they'll be visible when running tests.
|
||||
println!("Logs from your program will appear here!");
|
||||
let udp_socket = UdpSocket::bind("127.0.0.1:2053").expect("Failed to bind to address");
|
||||
let mut buf = [0; 512];
|
||||
|
||||
// Uncomment this block to pass the first stage
|
||||
// let udp_socket = UdpSocket::bind("127.0.0.1:2053").expect("Failed to bind to address");
|
||||
// let mut buf = [0; 512];
|
||||
//
|
||||
// loop {
|
||||
// match udp_socket.recv_from(&mut buf) {
|
||||
// Ok((size, source)) => {
|
||||
// let _received_data = String::from_utf8_lossy(&buf[0..size]);
|
||||
// println!("Received {} bytes from {}", size, source);
|
||||
// let response = [];
|
||||
// udp_socket
|
||||
// .send_to(&response, source)
|
||||
// .expect("Failed to send response");
|
||||
// }
|
||||
// Err(e) => {
|
||||
// eprintln!("Error receiving data: {}", e);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
loop {
|
||||
match udp_socket.recv_from(&mut buf) {
|
||||
Ok((size, source)) => {
|
||||
let _received_data = String::from_utf8_lossy(&buf[0..size]);
|
||||
println!("Received {} bytes from {}", size, source);
|
||||
let response = [];
|
||||
udp_socket
|
||||
.send_to(&response, source)
|
||||
.expect("Failed to send response");
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("Error receiving data: {}", e);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user