From b0531deb257332f46fc76de16d3a17fb3b28acee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=9CM=C3=9C=C5=9E?= <96421894+Tahinli@users.noreply.github.com> Date: Sat, 21 Oct 2023 21:47:16 +0300 Subject: [PATCH 1/2] feat: bidirectional transfer --- src/main.rs | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/src/main.rs b/src/main.rs index afd1683..49aeb6f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -367,16 +367,8 @@ impl Connection { Ok(mut stream) => { - let mut stay = true; - while stay - { - println!("Connected"); - let start_time = Instant::now(); - FileInfo::writing_operations(file_info, &mut stream, &debug_mode); - let finish_time = Instant::now(); - println!("Passed: Total -> {:#?}", finish_time.duration_since(start_time)); - stay = false; - } + println!("Connected"); + send_or_receive(file_info, &mut stream, &debug_mode); } Err(e) => { @@ -408,10 +400,7 @@ impl Connection Ok(mut stream) => { println!("Connected"); - let start_time = Instant::now(); - FileInfo::reading_operations(file_info, &mut stream, &debug_mode); - let finish_time = Instant::now(); - println!("Passed: Total -> {:#?}", finish_time.duration_since(start_time)); + send_or_receive(file_info, &mut stream, &debug_mode); } Err(e) => { @@ -421,7 +410,31 @@ impl Connection } } - +fn send_or_receive(file_info:&mut FileInfo, stream:&mut TcpStream, debug_mode:&bool) + { + match &take_string("Input: Send 's', Receive 'r'".to_string())[..1] + { + "s" => + { + println!("Connected"); + let start_time = Instant::now(); + FileInfo::reading_operations(file_info, stream, &debug_mode); + let finish_time = Instant::now(); + println!("Passed: Total -> {:#?}", finish_time.duration_since(start_time)); + } + "r" => + { + let start_time = Instant::now(); + FileInfo::writing_operations(file_info, stream, &debug_mode); + let finish_time = Instant::now(); + println!("Passed: Total -> {:#?}", finish_time.duration_since(start_time)); + } + input => + { + println!("Error: Give Valid Input, You Gave : {}", input); + panic!() } + } + } fn take_string(output:String) -> String { let mut input = String::new(); From d5d0f3121275c675ef40fc908143b280430acd1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=9CM=C3=9C=C5=9E?= <96421894+Tahinli@users.noreply.github.com> Date: Sat, 21 Oct 2023 21:53:03 +0300 Subject: [PATCH 2/2] doc: edit readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 530b6b4..ba2683f 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ TCP File Transfer Server and Client in Rust ☑ Remove memory limitations. [d42412c](https://github.com/Tahinli/rust-tcp-file-transfer/pull/1/commits/d42412c57d7d95672ba64b3e489b95f1c4b04a08) -☐ Bidirectional transfer. +☑ Bidirectional transfer. [b0531de] (https://github.com/Tahinli/rust-tcp-file-transfer/commit/b0531deb257332f46fc76de16d3a17fb3b28acee) ☐ Folder transfer.