summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
authortom barrett <spalf0@gmail.com>2018-02-20 09:51:10 -0600
committertom barrett <spalf0@gmail.com>2018-02-20 09:51:10 -0600
commit6fb01a0cb228b1aa08e47e8dbcd6b46c43bde06b (patch)
tree65e70e23ec229decc000be66e98b13d1c5ee06e0 /src/bin
-starting out
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/client.rs50
-rw-r--r--src/bin/server.rs24
2 files changed, 74 insertions, 0 deletions
diff --git a/src/bin/client.rs b/src/bin/client.rs
new file mode 100644
index 0000000..2dd4d7d
--- /dev/null
+++ b/src/bin/client.rs
@@ -0,0 +1,50 @@
+use std::io;
+use std::thread;
+use std::io::BufReader;
+use std::io::prelude::*;
+use std::net::{TcpStream, Shutdown};
+
+extern crate space;
+use space::ship::Ship;
+
+extern crate serde_json;
+
+fn get_login_info() -> String {
+ let mut name = String::new();
+ println!("Ship Name:");
+ io::stdin().read_line(&mut name).expect("Failed");
+
+ let mut password = String::new();
+ println!("Password:");
+ io::stdin().read_line(&mut password).expect("Failed");
+
+ name.replace("\n", "") + ":" + &password
+}
+
+fn main() {
+ let mut stream = TcpStream::connect("localhost:6000").unwrap();
+ let mut buff_r = BufReader::new(stream.try_clone().unwrap());
+
+ let send = get_login_info();
+ stream.write(send.as_bytes());
+
+ let mut data = String::new();
+ buff_r.read_line(&mut data);
+ let modules : Vec<&str> = data.split(",").collect();
+
+ println!("Choose your module:");
+ for (i, module) in modules.iter().enumerate() {
+ println!("{}) {}", i, module);
+ }
+
+ let mut choice = String::new();
+ io::stdin().read_line(&mut choice).expect("Failed");
+ stream.write(choice.as_bytes());
+
+ let mut data = String::new();
+ buff_r.read_line(&mut data);
+ let ship : Ship = serde_json::from_str(&data).unwrap();
+ println!("{:?}", ship.location.0);
+
+ stream.shutdown(Shutdown::Both);
+}
diff --git a/src/bin/server.rs b/src/bin/server.rs
new file mode 100644
index 0000000..71541f8
--- /dev/null
+++ b/src/bin/server.rs
@@ -0,0 +1,24 @@
+use std::io::prelude::*;
+use std::net::{TcpListener, TcpStream};
+
+extern crate space;
+use space::connection::Connection;
+
+fn main() {
+ let listener = TcpListener::bind("localhost:6000").unwrap();
+ listener.set_nonblocking(true);
+
+ let mut connections = Vec::new();
+ loop {
+ for stream in listener.incoming() {
+ match stream {
+ Ok(stream) => connections.push(Connection::new(stream)),
+ _ => (),
+ }
+ for i in 0..connections.len() {
+ connections[i].process();
+ }
+ connections.retain(|connection| connection.open );
+ }
+ }
+}