You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
1.9 KiB
67 lines
1.9 KiB
extern crate thread_priority;
|
|
use thread_priority::*;
|
|
use std::net::{TcpStream};
|
|
use std::io::prelude::*;
|
|
use std::io::{BufReader};
|
|
use std::time::{Duration};
|
|
use std::thread;
|
|
|
|
mod encoder;
|
|
|
|
use encoder::Encodestate;
|
|
|
|
pub static DEBUG: bool = false;
|
|
|
|
fn main() {
|
|
let thread_id = thread_native_id();
|
|
assert!(set_thread_priority(thread_id,
|
|
ThreadPriority::Max,
|
|
ThreadSchedulePolicy::Normal(NormalThreadSchedulePolicy::Normal)).is_ok());
|
|
|
|
let address = "192.168.1.77:8000";
|
|
let stream: TcpStream = TcpStream::connect(address).expect("connection failed");
|
|
let mut outstream = stream.try_clone().unwrap();
|
|
let mut reader = BufReader::new(stream);
|
|
let mut instructions;
|
|
let input = String::from("0123456789aBcDeFhijlnOpTuY ");
|
|
|
|
let mut state = Encodestate::new();
|
|
|
|
let mut headline = String::new();
|
|
reader.read_line(&mut headline).expect("Reading line failed");
|
|
println!("{}", headline);
|
|
|
|
for c in input.chars() {
|
|
instructions = state.encode_next_char(c);
|
|
for inst in instructions {
|
|
let mut response = String::new();
|
|
if DEBUG {
|
|
print!("{} ",inst);
|
|
}
|
|
writeln!(outstream, "{}", inst).expect("write failed");
|
|
reader.read_line(&mut response).expect("Reading line failed");
|
|
if DEBUG {
|
|
println!("{} ",response);
|
|
}
|
|
if !response.trim_end().contains("OK") {
|
|
return;
|
|
}
|
|
}
|
|
//thread::sleep(Duration::from_millis(500));
|
|
}
|
|
let mut response = String::new();
|
|
let inst = String::from("exit");
|
|
if DEBUG {
|
|
print!("{} ",inst);
|
|
}
|
|
writeln!(outstream, "{}", inst).expect("write failed");
|
|
reader.read_line(&mut response).expect("Reading line failed");
|
|
if DEBUG {
|
|
println!("{}", response);
|
|
}
|
|
|
|
if !response.trim_end().contains("OK") {
|
|
return;
|
|
}
|
|
|
|
}
|
|
|