diff --git a/src/bin/transistor-client.rs b/src/bin/transistor-client.rs index 87b05b0..680bf0a 100644 --- a/src/bin/transistor-client.rs +++ b/src/bin/transistor-client.rs @@ -22,7 +22,5 @@ fn main() -> Result<(), Error> { let mut client = Client::new(server, 1.0)?; client.start()?; - loop {} - Ok(()) } diff --git a/src/client.rs b/src/client.rs index 2acbe9f..9caf37a 100644 --- a/src/client.rs +++ b/src/client.rs @@ -8,6 +8,7 @@ use bincode::deserialize; use display_info::DisplayInfo; use serde::{Deserialize, Serialize}; +use crate::comm::*; use crate::display::*; use crate::*; @@ -104,7 +105,17 @@ impl Client { println!("[INF] connected!"); - Ok(()) + loop { + if let Err(e) = tcp_read(&mut self.tcp, &mut buffer) { + return Err(Error::new( + UnexpectedEof, + format!("warp in failed: {:?}", e), + )); + }; + + let msg: Message = deserialize(&buffer).unwrap(); + println!("[DBG] msg: {:?}", msg); + } } fn set_display_position(&mut self, server_conf: Vec) { diff --git a/src/server.rs b/src/server.rs index 7656ed4..1235f8a 100644 --- a/src/server.rs +++ b/src/server.rs @@ -334,26 +334,35 @@ fn transceive( // check if there is something to transmit match rx.try_recv() { Ok(msg) => { - println!("msg: {:?}", msg); - // TODO: transmit - } - Err(TryRecvError::Empty) => { - // do nothing + println!("[DBG] msg: {:?}", msg); + + if let Err(e) = tcp_write(&mut cur.tcp, msg) { + eprintln!("[ERR] msg transfer failed: {}", e); + continue; + } + + loop { + // check if cursor warped back + if let Err(e) = tcp_read(&mut cur.tcp, &mut buffer) { + if e.kind() == WouldBlock { + continue; + } + + // TODO: proper error handling + println!("[DBG] tcperr: {:?}", e); + + break; + } + + println!("[DBG] cursor warped back!"); + break; + } } + Err(TryRecvError::Empty) => {} // do nothing on empty recv Err(e) => { eprintln!("[ERR] message receive failed: {}", e); } } - - // check if cursor warped back - if let Err(e) = tcp_read(&mut cur.tcp, &mut buffer) { - if e.kind() == WouldBlock { - continue; - } - println!("tcperr: {:?}", e); - - continue; - } } }