blob: 663818a29876a385eb82bdb95339df96ddc334f8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
use std::io::BufReader;
use std::io::BufRead;
use std::net::TcpStream;
use std::io::Write;
use std::collections::HashMap;
extern crate serde_json;
use mass::Mass;
use ship::Ship;
use connection::Connection;
pub fn client_dashboard(mut buff_r : BufReader<TcpStream>) {
loop {
let mut recv = String::new();
buff_r.read_line(&mut recv).unwrap();
let ship : Ship = serde_json::from_str(&recv).unwrap();
println!("{:?}", ship);
}
}
impl Connection {
pub fn server_dashboard(&mut self, masses : &mut HashMap<String, Box<Mass>>) -> bool {
let ship = masses.get(&self.name).unwrap();
let send = ship.serialize() + "\n";
match self.stream.write(send.as_bytes()) {
Ok(_result) => true,
Err(_error) => false,
}
}
}
|