Hi! I want my program to be a server and a client at the same time. This is what I've written so far. How can I finish it?
pub fn run()
{
let sendSocket = std::net::TcpListener::bind("127.0.0.1:4440").expect("");
println!("Waiting...");
let (mut socket, addr) = sendSocket.accept().expect("");
println!("Connected! {}", addr);
let receive = std::thread::spawn( ||{
let mut inputBuffer = vec![0; 1024];
socket.read_exact(&mut inputBuffer).expect("");
let msg = inputBuffer.into_iter().take_while(|&x| x != 0).collect::<Vec<_>>();
let msg = String::from_utf8(msg).expect("");
println!("-{}", msg);
});
let send = std::thread::spawn(|| {
let mut sendMsg = String::new();
std::io::stdin().read_line(&mut sendMsg).expect("");
sendMsg = sendMsg.trim().to_string();
let mut buff = sendMsg.clone().into_bytes();
buff.resize(1024, 0);
socket.write_all(&buff).expect("");
});
The problem is that after I move the socket to the sender I can't receive anything.
Thanks in advance!