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