2020-10-27 03:27:25 +00:00
|
|
|
use std::{
|
|
|
|
error::Error,
|
|
|
|
sync::Arc,
|
|
|
|
};
|
2020-10-27 02:49:12 +00:00
|
|
|
|
|
|
|
use hyper::{
|
|
|
|
StatusCode,
|
|
|
|
Uri,
|
|
|
|
};
|
|
|
|
use reqwest::Client;
|
|
|
|
use tokio::fs::File;
|
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main () -> Result <(), Box <dyn Error>> {
|
2020-10-27 03:27:25 +00:00
|
|
|
let client = Arc::new (Client::new ());
|
2020-10-27 02:49:12 +00:00
|
|
|
|
|
|
|
let path = "/home/user/pictures/bzqcChY.jpg";
|
|
|
|
|
|
|
|
loop {
|
|
|
|
let _uri = Uri::builder ()
|
|
|
|
.scheme ("http")
|
|
|
|
.authority ("127.0.0.1:4000")
|
2020-10-27 03:27:25 +00:00
|
|
|
.path_and_query ("/http_listen/alien_wildlands")
|
2020-10-27 02:49:12 +00:00
|
|
|
.build ().unwrap ();
|
|
|
|
|
2020-10-27 03:27:25 +00:00
|
|
|
let req_req = client.get ("http://127.0.0.1:4000/http_listen/alien_wildlands");
|
|
|
|
|
|
|
|
println! ("Step 1");
|
|
|
|
let req_resp = match req_req.send ().await {
|
2020-10-27 02:49:12 +00:00
|
|
|
Err (e) => {
|
|
|
|
println! ("Err: {:?}", e);
|
|
|
|
continue;
|
|
|
|
},
|
|
|
|
Ok (r) => r,
|
|
|
|
};
|
|
|
|
|
2020-10-27 03:27:25 +00:00
|
|
|
if req_resp.status () != StatusCode::OK {
|
2020-10-27 02:49:12 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-10-27 03:27:25 +00:00
|
|
|
println! ("Step 3");
|
|
|
|
|
|
|
|
let body = req_resp.bytes ().await?;
|
|
|
|
let body = String::from (std::str::from_utf8 (&body)?);
|
2020-10-27 02:49:12 +00:00
|
|
|
|
|
|
|
println! ("Client requested {}", body);
|
2020-10-27 03:27:25 +00:00
|
|
|
|
|
|
|
println! ("Step 4/5");
|
2020-10-27 03:36:52 +00:00
|
|
|
let payload = String::from ("Ha ha hue hue it worked.\n");
|
2020-10-27 03:27:25 +00:00
|
|
|
|
|
|
|
println! ("Step 6");
|
|
|
|
let client = client.clone ();
|
|
|
|
tokio::spawn (async move {
|
|
|
|
let resp_req = Uri::builder ()
|
|
|
|
.scheme ("http")
|
|
|
|
.authority ("127.0.0.1:4000")
|
|
|
|
.path_and_query ("/listen/alien_wildlands")
|
|
|
|
.build ().unwrap ();
|
|
|
|
|
2020-10-27 03:36:52 +00:00
|
|
|
let resp_req = client.post (&format! ("http://127.0.0.1:4000/http_response/{}", body)).body (payload);
|
2020-10-27 03:27:25 +00:00
|
|
|
|
|
|
|
println! ("Step 6");
|
|
|
|
match resp_req.send ().await {
|
|
|
|
Err (e) => {
|
|
|
|
println! ("Err: {:?}", e);
|
|
|
|
},
|
|
|
|
Ok (_) => (),
|
|
|
|
}
|
|
|
|
});
|
2020-10-27 02:49:12 +00:00
|
|
|
}
|
|
|
|
}
|