src/test.rs hinzugefügt
This commit is contained in:
16
src/test.rs
Normal file
16
src/test.rs
Normal file
@@ -0,0 +1,16 @@
|
||||
use std::net::UdpSocket;
|
||||
|
||||
//call from main fn
|
||||
pub fn sendtestudp(to: String, port: u16, payload: String) {
|
||||
let socket = UdpSocket::bind("0.0.0.0:0").expect("couldn't bind to address");
|
||||
let to = format!("{}:{}", to, port);
|
||||
|
||||
//form hex string to real hex -> FF == 0xFF
|
||||
let bytes: Vec<u8> = (0..payload.len())
|
||||
.step_by(2)
|
||||
.map(|i| u8::from_str_radix(&payload[i..i+2], 16).expect("not a real hex"))
|
||||
.collect();
|
||||
|
||||
socket.send_to(&bytes, to);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user