projects
/
crypto_lab1.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Change the structure of a packet.
[crypto_lab1.git]
/
src
/
client.rs
diff --git
a/src/client.rs
b/src/client.rs
index
575df05
..
14df2d4
100644
(file)
--- a/
src/client.rs
+++ b/
src/client.rs
@@
-1,5
+1,5
@@
use std::io::{ TcpStream, IoResult };
use std::io::{ TcpStream, IoResult };
-use
command::{ Command, Packet, Error
};
+use
packet::{ Command, Packet
};
pub struct Client {
socket: TcpStream,
pub struct Client {
socket: TcpStream,
@@
-14,19
+14,23
@@
impl Client {
})
}
})
}
- pub fn close(&mut self) {
- self.socket.close_read();
- self.socket.close_write();
+ pub fn close(&mut self) -> IoResult<()> {
+ try!(self.socket.close_read());
+ try!(self.socket.close_write());
+ Ok(())
}
pub fn start_tests(&mut self) {
}
pub fn start_tests(&mut self) {
-
- let command = Packet::new_random_command(self.current_timestamp);
- self.send(command);
-
+ self.current_timestamp += 1;
+ let timestamp = self.current_timestamp;
+ self.send(Packet { timestamp: timestamp, t: Command(Packet::random_packet_data()) });
}
}
- fn send(&mut self, p: Packet) {
- p.write(&mut self.socket);
+ fn send(&mut self, p: Packet) {
+ println!("Client sends packet: {}", p);
+ match p.write(&mut self.socket) {
+ Err(e) => println!("Error on sending: {}", e),
+ _ => ()
+ }
}
}
\ No newline at end of file
}
}
\ No newline at end of file