-use std::io::{ TcpStream, IoResult };
-use packet::{ Command, Packet };
-
-pub struct Client {
- socket: TcpStream,
- current_timestamp: u64
-}
-
-impl Client {
- pub fn new(address: &str, port: u16) -> IoResult<Client> {
- Ok(Client {
- socket: try!(TcpStream::connect(address, port)),
- current_timestamp: 0
- })
- }
-
- pub fn close(&mut self) -> IoResult<()> {
- try!(self.socket.close_read());
- try!(self.socket.close_write());
- Ok(())
- }
-
- pub fn start_tests(&mut self) {
- 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) {
- println!("Client sends packet: {}", p);
- match p.write(&mut self.socket) {
- Err(e) => println!("Error on sending: {}", e),
- _ => ()
- }
- }
-}
\ No newline at end of file