intel_cache_lib/
ic_client.rs1use std::net::TcpStream;
2use std::io::{ErrorKind,Error};
3use crate::ic_types::{IcConnection,IcPacket};
4
5pub struct IcClient {
7 pub con: IcConnection
9}
10impl IcClient {
11 pub fn connect(ip: &str,testing: bool) -> Result<IcClient,Error> {
17 if ! testing {
18 let con = TcpStream::connect(ip.to_owned()+":64209");
19 if let Ok(c) = con {
20 return Ok(IcClient { con: IcConnection::new(c,testing) });
21 } else {
22 return Err(Error::new(ErrorKind::Other,"Failed to connect."));
23 }
24 } else {
25 let con = TcpStream::connect(ip.to_owned()+":46290");
26 if let Ok(c) = con {
27 return Ok(IcClient { con: IcConnection::new(c,testing) });
28 } else {
29 return Err(Error::new(ErrorKind::Other,"Failed to connect."));
30 }
31 }
32 }
33
34 pub fn send_cmd(&mut self,c: &mut IcPacket) -> IcPacket {
38 self.con.send_packet(c).unwrap();
46 let retp = self.con.get_packet().unwrap_or(IcPacket::new_empty());
47 return retp;
48 }
49}
50