title: Curiosity about Java sockets and printstream
body: <p>I'm learning some Java socket programming and I've managed to make my first ever connection between Server and Client. That sparked a curiosity in me: what would happen if instead of the "Connected" and "Message Received" messages I made a sort of "chat room" type thing, where server and client inputs are printed to one another? So I tried doing just that.</p>
  
  <p>Now, I know this isn't the way chat rooms are created (I'd probably need Threads and whatnot), but I was very curious as to why this didn't work:</p>
  
  <p>Server:</p>
  
  <pre><code>public void run() throws Exception
  {
      boolean isChatting = true;
      Socket clientSocket = new Socket("localhost", 444);
  
      PrintStream ps = new PrintStream(clientSocket.getOutputStream());
      ps.println("Connected.");
  
      BufferedReader bfr = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
      BufferedReader bfrClient = new BufferedReader(new InputStreamReader(System.in));
  
      String serverMessage = bfr.readLine();
      String clientMessage;
  
      System.out.println("Server: "+serverMessage);
  
      while (isChatting)
      {
          clientMessage = bfrClient.readLine();
          ps.println(clientMessage);
  
          if (clientMessage.toUpperCase().equals("EXIT"))
          {
              isChatting = false;
          }
      }
  
      bfr.close();
      bfrClient.close();
  }
  </code></pre>
  
  <p>Client:</p>
  
  <pre><code>public void run() throws Exception
  {
      boolean isChatting = true;
      ServerSocket server = new ServerSocket(444); //Port
      Socket sSocket = server.accept();
      PrintStream ps = new PrintStream(sSocket.getOutputStream());
  
      BufferedReader bfr = new BufferedReader(new InputStreamReader(sSocket.getInputStream()));
      BufferedReader bfrPersonal = new BufferedReader(new InputStreamReader(System.in));
  
      String clientMessage = bfr.readLine();
      String messageToSend;
      System.out.println("Client: "+clientMessage);
  
      if (clientMessage != null)
      {
          ps.println("Connected.");
      }
  
      while (isChatting)
      {
          messageToSend = bfrPersonal.readLine();
          ps.println(messageToSend);
  
          if (messageToSend.toUpperCase().equals("EXIT"))
          {
              isChatting = false;
          }
      }
  
      bfr.close();
      bfrPersonal.close();
  }
  </code></pre>
  
  <p>Thank you for your time! :)</p>