DAMN YOU RUST
This commit is contained in:
parent
817e08e89b
commit
14121fed8d
@ -5,14 +5,15 @@ extern crate serde_json;
|
||||
extern crate serde_derive;
|
||||
|
||||
use a03::*;
|
||||
use std::net::{TcpListener, TcpStream, Shutdown};
|
||||
use std::net::{TcpListener, TcpStream, Shutdown, SocketAddrV4, Ipv4Addr};
|
||||
use std::borrow::Cow;
|
||||
use std::thread;
|
||||
use std::io::Read;
|
||||
use std::io::Write;
|
||||
|
||||
fn main() {
|
||||
let mut stream = TcpStream::connect("localhost:6770").unwrap();
|
||||
let endpoint = parse_endpoint_from_cli(0);
|
||||
let mut stream = TcpStream::connect(endpoint).unwrap();
|
||||
serde_json::to_writer(
|
||||
&mut stream,
|
||||
&Packet {
|
||||
@ -20,12 +21,11 @@ fn main() {
|
||||
json: None,
|
||||
})
|
||||
.unwrap();
|
||||
println!("Message sent!");
|
||||
stream.flush().unwrap();
|
||||
stream.shutdown(Shutdown::Write).unwrap();
|
||||
let files: FilePaths = serde_json::from_reader(&mut stream).unwrap();
|
||||
for path in files.paths.iter() {
|
||||
println!("Path: {}", path);
|
||||
println!("/home/{}", path);
|
||||
}
|
||||
}
|
||||
|
||||
|
17
src/lib.rs
17
src/lib.rs
@ -5,6 +5,11 @@ extern crate serde_derive;
|
||||
|
||||
use std::borrow::Cow;
|
||||
use std::net::Ipv4Addr;
|
||||
use std::net::SocketAddrV4;
|
||||
use std::str::FromStr;
|
||||
//use std::
|
||||
|
||||
const DEFAULT_PORT: &str = "8000";
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub enum PacketType {
|
||||
@ -81,3 +86,15 @@ pub struct BlockQuery {
|
||||
pub data_node: DataNode,
|
||||
pub chunk_id: String
|
||||
}
|
||||
|
||||
pub fn parse_endpoint_from_cli(arg_index : usize) -> String {
|
||||
let mut args: Vec<String> = std::env::args().skip(1).collect();
|
||||
let endpoint_arg: String = args.get(arg_index).expect("No IP provided").clone();
|
||||
|
||||
if endpoint_arg.contains(":") {
|
||||
endpoint_arg
|
||||
} else {
|
||||
format!("{}:{}", endpoint_arg, DEFAULT_PORT)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user