work connection

This commit is contained in:
Guillermo Roche 2022-09-19 23:30:35 +02:00
parent 8266ef59e0
commit 464b661bd7
24 changed files with 25 additions and 17 deletions

View File

@ -1,7 +1,7 @@
use std::net::TcpStream;
use std::io::prelude::*;
use std::thread;
use std::sync::{Arc, Mutex};
use std::sync::{Arc, Mutex, RwLock};
mod HandShake;
@ -11,7 +11,7 @@ pub struct Client<'a>{
//client: &'static TcpStream,
//server: &'static TcpStream,
hs: HandShake::HandShake<'a>,
run : Arc<Mutex<bool>>,
run : Arc<RwLock<bool>>,
//run: &'static bool
}
@ -23,7 +23,7 @@ impl<'a> Client<'a> {
//client: client,
//server: server,
hs: HandShake::HandShake::new(handshake),
run: Arc::new(Mutex::new(true)),
run: Arc::new(RwLock::new(true)),
//run: &true,
}
}
@ -34,19 +34,23 @@ impl<'a> Client<'a> {
fn join_conexions_mutex(c1: Arc<Mutex<TcpStream>>,
c2: Arc<Mutex<TcpStream>>,
run: Arc<Mutex<bool>>,
run: Arc<RwLock<bool>>,
id: i32){
let mut buf: [u8; 1000000] = [0; 1000000];
while *run.lock().unwrap() {
let mut client = c1.lock().unwrap().try_clone().unwrap();
while *run.read().unwrap() {
println!("read{}",id);
let res=c1.lock().unwrap().read(&mut buf);
let res=client.read(&mut buf);
match res {
Ok(leng) => {
println!("rx {}",leng);
if leng == 0 {
*run.write().unwrap()=false;
}
println!("tx {}",c2.lock().unwrap().write(&buf [.. leng]).unwrap());
},
//Ok(leng) => {c2.lock().unwrap().write(&buf);},
Err(_e) => {*run.lock().unwrap()=false;},
Err(_e) => {*run.write().unwrap()=false;},
}
println!("write{}",id);

View File

@ -4,7 +4,7 @@ mod client;
fn main() {
let listener = TcpListener::bind("127.0.0.1:25567").unwrap();
let mut buf: [u8; 128] = [1; 128];
let mut buf: [u8; 256] = [1; 256];
for stream in listener.incoming() {
//stream.unwrap().write(buf);
match stream {
@ -15,13 +15,17 @@ fn main() {
stream.flush();*/
println!("Go!");
let leng = stream.read(&mut buf).unwrap();
buf[(buf[0]-1) as usize] += 2;
let mut sstream = TcpStream::connect("127.0.0.1:25565").unwrap();
sstream.write(&buf[.. leng]);
let c1 = client::Client::new(stream,sstream, &buf);
c1.to_string();
c1.start_proxy().0.join();
c1.start_proxy().1.join();
println!("{}", leng);
if buf[0] < 200 {
buf[(buf[0]-1) as usize] += 2;
let mut sstream = TcpStream::connect("127.0.0.1:25565").unwrap();
sstream.write(&buf[.. leng]);
let c1 = client::Client::new(stream,sstream, &buf);
c1.to_string();
c1.start_proxy();
}
//c1.start_proxy().0.join();
//c1.start_proxy().1.join();
},
Err(_e) => println!("{}",_e),

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long