title: Where does the data go when writing to a socket in java?
body: <p>Say I have the following code which sets up a Socket and a in and out stream for reading and writing to the socket.</p>
  
  <pre><code>toMonitor = new Socket(sd.m_sMonName, sd.m_iMonPort);
  out = new PrintWriter(toMonitor.getOutputStream(), true);
  in = new BufferedReader(new InputStreamReader(toMonitor.getInputStream()));
  </code></pre>
  
  <p>Also say I have the method below called SendIt, which writes a String to the Sockets outputstream</p>
  
  <pre><code>public void SendIt (String message) throws IOException 
  {
      try 
      {        
          newStatus("MessageParser [SendIt]: sent:\n\t" + message, true);
  
          out.println(message);
          if (out.checkError() == true) 
              throw (new IOException());
          out.flush();
          if (out.checkError() == true) 
              throw (new IOException());
      } 
      catch (IOException e) {} //Bubble the Exception upwards
  }
  </code></pre>
  
  <p>When I call <code>out.println(message);</code> above, will that message sit in the buffer until the other end of the socket reads it? 
  - I take it the underlying writer object will break it into bytes, send it to the Sockets output stream where it is assembled into packets and sent out, thus clearing the Buffer as it is written?</p>
  
  <p>Will it sit there until I call <code>out.flush()</code>? </p>
  
  <p>Does <code>out.flush()</code> ALWAYS clear the buffer, or could something stay in there, somehow..?</p>
  
  <p>EDIT: </p>
  
  <p>I am currently using Netbeans as my IDE, is there are way in which I could watch the actual value of the output buffer in real time as the program runs?</p>