summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/client.rs35
-rw-r--r--src/bin/server.rs27
2 files changed, 33 insertions, 29 deletions
diff --git a/src/bin/client.rs b/src/bin/client.rs
index 2dd4d7d..6f4a8fc 100644
--- a/src/bin/client.rs
+++ b/src/bin/client.rs
@@ -1,15 +1,15 @@
use std::io;
-use std::thread;
-use std::io::BufReader;
use std::io::prelude::*;
-use std::net::{TcpStream, Shutdown};
+use std::io::BufReader;
+use std::net::TcpStream;
extern crate space;
-use space::ship::Ship;
+use space::dashboard::Dashboard;
+use space::engines::Engines;
+use space::module::{Module, from_primitive};
-extern crate serde_json;
-fn get_login_info() -> String {
+fn get_info() -> String {
let mut name = String::new();
println!("Ship Name:");
io::stdin().read_line(&mut name).expect("Failed");
@@ -22,29 +22,30 @@ fn get_login_info() -> String {
}
fn main() {
+ let send = get_info();
+
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());
+ stream.write(send.as_bytes()).unwrap();
let mut data = String::new();
- buff_r.read_line(&mut data);
+ buff_r.read_line(&mut data).unwrap();
let modules : Vec<&str> = data.split(",").collect();
println!("Choose your module:");
for (i, module) in modules.iter().enumerate() {
- println!("{}) {}", i, module);
+ println!("{}) {}", i, module.replace("\n", ""));
}
let mut choice = String::new();
io::stdin().read_line(&mut choice).expect("Failed");
- stream.write(choice.as_bytes());
+ stream.write(choice.as_bytes()).unwrap();
- 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);
+ let module = from_primitive(choice);
+ match module {
+ Module::Dashboard => Dashboard(buff_r),
+ Module::Engines => Engines(stream),
+ _ => (),
+ }
}
diff --git a/src/bin/server.rs b/src/bin/server.rs
index 71541f8..871315e 100644
--- a/src/bin/server.rs
+++ b/src/bin/server.rs
@@ -1,24 +1,27 @@
-use std::io::prelude::*;
-use std::net::{TcpListener, TcpStream};
+use std::thread::sleep;
+use std::time::Duration;
+use std::net::TcpListener;
extern crate space;
use space::connection::Connection;
fn main() {
let listener = TcpListener::bind("localhost:6000").unwrap();
- listener.set_nonblocking(true);
+ listener.set_nonblocking(true).unwrap();
let mut connections = Vec::new();
- loop {
- for stream in listener.incoming() {
- match stream {
- Ok(stream) => connections.push(Connection::new(stream)),
- _ => (),
+ for stream in listener.incoming() {
+ match stream {
+ Ok(stream) => connections.push(Connection::new(stream)),
+ _ => {
+ println!("looped");
+ for i in 0..connections.len() {
+ connections[i].process();
+ }
+ connections.retain(|connection| connection.open );
+ sleep(Duration::from_millis(100));
}
- for i in 0..connections.len() {
- connections[i].process();
- }
- connections.retain(|connection| connection.open );
}
}
+
}