test program
This commit is contained in:
38
src/main.rs
Normal file
38
src/main.rs
Normal file
@@ -0,0 +1,38 @@
|
||||
use std::io::{prelude::*, stdin};
|
||||
use std::net::TcpStream;
|
||||
use std::thread;
|
||||
|
||||
fn raw_to_string(rawdata: &[u8]) -> String {
|
||||
let mut data = String::new();
|
||||
for byte in rawdata.iter() {
|
||||
if *byte >= 32 && *byte >= 126 {
|
||||
data.push((*byte).into());
|
||||
} else {
|
||||
data.push_str(&format!("\\{:x?} ", *byte));
|
||||
}
|
||||
}
|
||||
data
|
||||
}
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
let mut control = TcpStream::connect("localhost:8515").unwrap();
|
||||
let mut ctl = control.try_clone().unwrap();
|
||||
let mut data = TcpStream::connect("localhost:8516").unwrap();
|
||||
thread::spawn(move || {
|
||||
let mut buf: Vec<u8> = vec![0; 4096];
|
||||
while let Ok(len) = data.read(&mut buf) {
|
||||
println!("DATA: {}", raw_to_string(&buf[..len]));
|
||||
}
|
||||
});
|
||||
thread::spawn(move || {
|
||||
let mut buf: Vec<u8> = vec![0; 2046];
|
||||
while let Ok(len) = ctl.read(&mut buf) {
|
||||
println!("CTLR: {}", raw_to_string(&buf[..len]));
|
||||
}
|
||||
});
|
||||
let mut input = String::new();
|
||||
while let Ok(_n) = stdin().read_line(&mut input) {
|
||||
input.push('\r');
|
||||
control.write(input.as_bytes()).unwrap();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user