async_notify/
async_notify.rs

1extern crate ssdp;
2
3use std::io::{self, Read};
4use std::thread;
5use std::time::Duration;
6
7use ssdp::FieldMap;
8use ssdp::header::{HeaderMut, NT, NTS, USN};
9use ssdp::message::{NotifyListener, NotifyMessage, Listen, Multicast};
10
11fn main() {
12    thread::spawn(|| {
13        for (msg, src) in NotifyListener::listen().unwrap() {
14            println!("Received The Following Message From {}:\n{:?}\n", src, msg);
15        }
16    });
17
18    // Make Sure Thread Has Started
19    thread::sleep(Duration::new(1, 0));
20
21    // Create A Test Message
22    let mut message = NotifyMessage::new();
23
24    // Set Some Headers
25    message.set(NTS::ByeBye);
26    message.set(NT(FieldMap::upnp("rootdevice")));
27    message.set(USN(FieldMap::uuid("Hello, This Is Not A UUID!!!"), None));
28
29    message.multicast().unwrap();
30
31    // Wait Until User Is Done Listening For Notify Messages
32    println!("Press Enter When You Wish To Exit...\n");
33    let input = io::stdin();
34
35    input.bytes().next();
36}