blob: c2db59440362ead63272c5286658b04869ad3cf1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
use rust_threadx_imxrt1170evk as _;
use std::{net::UdpSocket, thread};
fn main() {
thread::scope(|scope| {
thread::Builder::new()
.stack_size(512)
.spawn_scoped(scope, count)
.unwrap();
udp_loopback();
})
}
fn count() -> ! {
let mut count = 0_usize;
loop {
println!("Hello world! The count is {count}");
count = count.wrapping_add(1);
std::thread::sleep(std::time::Duration::from_millis(500))
}
}
fn udp_loopback() -> ! {
let mut buffer = [0_u8; 1024];
let socket = UdpSocket::bind("192.168.5.1:5678").unwrap();
loop {
let (amt, src) = socket.recv_from(&mut buffer).unwrap();
let msg = &buffer[..amt];
println!(
"Received {amt} bytes from {src}: \"{}\"",
str::from_utf8(msg).unwrap()
);
socket.send_to(msg, &src).unwrap();
}
}
|