This is my server.
I want my server to get the value of variable B, change the value of A, and SAVE this chandes, and send to the client the new value of A in array[u8,50]
My question is how can I convert from string to utf8, but array[u8,50]?
fn handle_client(mut stream: TcpStream) {
let mut data = [0 as u8; 50]; // using 50 byte buffer
let mut a: i32 = 1;
while match stream.read(&mut data) {
Ok(size) => {
let temps = str::from_utf8(&data).unwrap(); //get the utf8 and made String
let temp: i32 = temps.parse().unwrap(); // convert from String to i32
// actually, I don't know, how to do in the way, when
// when my variable A doesn't change to the beginning value - 1,
// every time, when the client sends new value of B ??
a = a * temp;
let st = a.to_string(); // now, converting a:i32 to String
data = st.into_bytes(); // now I need to convert String to u8, but the error says:
// expected array [u8,50]
// found strust 'std::vec::Vec<u8>'
// so I need to convert String to array [u8,50], BUT HOW?
// echo everything!
stream.write(&data[0..size]).unwrap();
true
},
Err(_) => {
println!("An error occurred, terminating connection with {}", stream.peer_addr().unwrap());
stream.shutdown(Shutdown::Both).unwrap();
false
}
} {}
}