send input from client

This commit is contained in:
Niklas Eichenseer 2022-11-17 12:23:49 +01:00
parent 598245457e
commit 3691679be4

View File

@ -1,18 +1,20 @@
use std::io::Write;
use std::net::TcpStream;
fn main() {
let stream = TcpStream::connect("127.0.0.1:8080");
if stream.is_ok() {
println!("Connected to the server!");
} else {
println!("Couldn't connect to server...");
}
//let stream = TcpStream::connect("172.30.16.1:8080");
//let stream = TcpStream::connect("27.0.0.1:8080");
match TcpStream::connect("localhost:3333") {
Ok(mut stream) => {
println!("Successfully connected to server");
loop {
let mut buffer = String::new();
match std::io::stdin().read_line(&mut buffer){
Ok(_n) => {
println!("{}", buffer);
println!("Sending {}", buffer);
stream.write(buffer.as_bytes()).unwrap();
println!("Sent {}, awaiting reply...", buffer);
}
Err(_error) =>{
println!("Fehlerhafte Eingabe!");
@ -20,4 +22,10 @@ fn main() {
}
}
}
},
Err(e) => {
println!("Failed to connect: {}", e);
}
}
println!("Terminated.");
} // the stream is closed here