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() {
|
fn main() {
|
||||||
// You can use print statements as follows for debugging, they'll be visible when running tests.
|
let udp_socket = UdpSocket::bind("127.0.0.1:2053").expect("Failed to bind to address");
|
||||||
println!("Logs from your program will appear here!");
|
let mut buf = [0; 512];
|
||||||
|
|
||||||
// Uncomment this block to pass the first stage
|
loop {
|
||||||
// let udp_socket = UdpSocket::bind("127.0.0.1:2053").expect("Failed to bind to address");
|
match udp_socket.recv_from(&mut buf) {
|
||||||
// let mut buf = [0; 512];
|
Ok((size, source)) => {
|
||||||
//
|
let _received_data = String::from_utf8_lossy(&buf[0..size]);
|
||||||
// loop {
|
println!("Received {} bytes from {}", size, source);
|
||||||
// match udp_socket.recv_from(&mut buf) {
|
let response = [];
|
||||||
// Ok((size, source)) => {
|
udp_socket
|
||||||
// let _received_data = String::from_utf8_lossy(&buf[0..size]);
|
.send_to(&response, source)
|
||||||
// println!("Received {} bytes from {}", size, source);
|
.expect("Failed to send response");
|
||||||
// let response = [];
|
}
|
||||||
// udp_socket
|
Err(e) => {
|
||||||
// .send_to(&response, source)
|
eprintln!("Error receiving data: {}", e);
|
||||||
// .expect("Failed to send response");
|
break;
|
||||||
// }
|
}
|
||||||
// Err(e) => {
|
}
|
||||||
// eprintln!("Error receiving data: {}", e);
|
}
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user