X-Git-Url: http://git.euphorik.ch/?p=crypto_lab1.git;a=blobdiff_plain;f=src%2Fclient.rs;fp=src%2Fclient.rs;h=8392460e433169e5b74415a8b932efab6d5cb649;hp=0000000000000000000000000000000000000000;hb=aee28ef5d1be59c0db218d7130fd1ae2314cc970;hpb=73730f083cb2d305a039d49d9e34ff9978fe20be diff --git a/src/client.rs b/src/client.rs new file mode 100644 index 0000000..8392460 --- /dev/null +++ b/src/client.rs @@ -0,0 +1,35 @@ +use std::io::{ TcpStream, IoResult }; +use command::{ Command, Packet, Error }; +use crypto::Crypto; + +pub struct Client { + socket: TcpStream, + crypto: Crypto, + current_timestamp: u64 +} + +impl Client { + pub fn new(address: &str, port: u16) -> IoResult { + Ok(Client { + socket: try!(TcpStream::connect(address, port)), + current_timestamp: 0, + crypto: Crypto::new() + }) + } + + pub fn close(&mut self) { + self.socket.close_read(); + self.socket.close_write(); + } + + pub fn start_tests(&mut self) { + + let command = Packet::newRandomCommand(self.current_timestamp); + self.send(command); + + } + + fn send(&mut self, p: Packet) { + p.write(&mut self.socket); + } +} \ No newline at end of file