title: Simple Rust TCP server and client do not receive messages and never terminates
body: <p>I am trying to spawn a server and connect to it on a different thread. I know Rust has blocking I/O, but I feel like I should be able to connect a server in a different thread. I do not have a lot of knowledge in threads. The end game is to connect to this server across a network. That is what I am simulating with the <code>player_stream</code> <code>TCPStream</code>. The <code>player_stream</code> will wait until there is something in its buffer. Once something has been written there, it will respond back to the server. As is, the program will not terminate.</p>
  
  <pre><code>use std::net::{TcpListener, TcpStream};
  use std::io::{BufReader,BufWriter};
  use std::io::Write;
  use std::io::Read;
  use std::thread;
  
  fn main() {
      thread::spawn(move || {
          start_server();
      });
      let player_stream = TcpStream::connect("127.0.0.1:8000").expect("Couldn't connect");
      let mut reader = BufReader::new(&amp;player_stream);
      let mut response = String::new();
      reader.read_to_string(&amp;mut response);
      println!("Player received {}", response);
      let mut writer = BufWriter::new(&amp;player_stream);
      writer.write_all("NAME".as_bytes());
  }
  
  fn start_server() {
      let listener = TcpListener::bind("127.0.0.1:8000").unwrap();
  
      fn handle_client(stream: TcpStream) {
          println!("Client connected");
          let mut writer = BufWriter::new(&amp;stream);
          writer.write_all("Red".as_bytes());
          let mut reader = BufReader::new(&amp;stream);
          let mut response = String::new();
          reader.read_to_string(&amp;mut response);
          println!("Server received {}", response);
  
      }
  
  // accept connections
      for stream in listener.incoming() {
          match stream {
              Ok(stream) =&gt; {
                  handle_client(stream);
              }
              Err(e) =&gt; { panic!("{}",e) }
          }
      }
  }
  </code></pre>