#client #ssdp #udp-client #functional #networking #payload

bin+lib simple-ssdp-client

A simple yet functional SSDP client written in Rust

5 releases

Uses old Rust 2015

0.1.5 Nov 25, 2019
0.1.4 Nov 25, 2019

#4 in #ssdp

Custom license

9KB
138 lines

A simple yet functional SSDP client written in Rust

A little personal experiment to:

  1. learn the Rust's networking (and specifically UDP related) APIs
  2. implement a working and easy to use SSDP Client
  3. learn a little more about SSDP

Currently, documentation and testing coverage is pretty lacking. This will be addressed in subsequent commits.

Building

cargo build

Release Candidate

cargo build --release

Running

Local Testing

$ ./target/debug/simple_ssdp_client --help

Release Candidate

$ ./target/release/simple_ssdp_client --help

Example Usage

As an App

$ ./target/debug/simple_ssdp_client --server=roku
{"server" : "roku/9.2.0 upnp/1.0 roku/9.2.0", "location: "http://192.168.1.25:8060/"}

Showing SSDP M-Search Payload

$ ./target/debug/simple_ssdp_client --print-payload

    M-SEARCH * HTTP/1.1
    Host: 239.255.255.250:1900
    Man: "ssdp:discover"
    ST: ssdp:all
    MX: 5

As a Lib

Cargo.toml

ssdp = { package = "simple-ssdp-client", version = "0.1.4" }

mod declaration

extern crate ssdp;

Code

# optionally if you wanted to use a server response outside of this context
let mut url = String::new(); 
let print_headers = |response_headers: &ResponseHeaders| {
    fn determine_server(abc: &ArgMatches) -> String {
        match abc.value_of("server_pattern") {
            Some(server) => { return String::from(server) }
            None => { return String::new() }
        };
    }
    let resolved_server = determine_server( &args());
    if response_headers.server.contains(resolved_server.as_str()) {
        println!("{{\"server\" : \"{}\", \"location: \"{}\"}}", response_headers.server, response_headers.location);
        url = response_headers.location.clone(); # see above
        exit(0);
    }
};

ssdp::listen( print_headers)

Dependencies

~750KB