Created
March 6, 2018 08:54
-
-
Save sgbasaraner/2400710a502a6f851eebd2eec359ea8d to your computer and use it in GitHub Desktop.
Revisions
-
sgbasaraner created this gist
Mar 6, 2018 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ use std::str; use std::thread; use std::net::UdpSocket; fn main() { let addr = "239.255.255.250:1982"; let socket = match UdpSocket::bind(addr) { Ok(s) => s, Err(e) => panic!("couldn't bind socket: {}", e) }; let message = "M-SEARCH * HTTP/1.1\r\n HOST: 239.255.255.250:1982\r\n MAN: \"ssdp:discover\"\r\n ST: wifi_bulb".as_bytes(); //socket.send_to(&message, addr).expect("couldn't send data"); socket.send_to(message, addr).expect("couldn't send to socket"); let mut buf = [0; 2048]; loop { match socket.recv_from(&mut buf) { Ok((amt, src)) => { thread::spawn(move || { println!("amt: {}", amt); println!("src: {}", src); println!("{}", str::from_utf8(&buf).unwrap_or("")); }); }, Err(e) => { println!("couldn't receive a datagram: {}", e); } } } }