Say I have the following code which sets up a Socket and a in and out stream for reading and writing to the socket.
toMonitor = new Socket(sd.m_sMonName, sd.m_iMonPort);
out = new PrintWriter(toMonitor.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(toMonitor.getInputStream()));
Also say I have the method below called SendIt, which writes a String to the Sockets outputstream
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
}
When I call out.println(message);
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?
Will it sit there until I call out.flush()
?
Does out.flush()
ALWAYS clear the buffer, or could something stay in there, somehow..?
EDIT:
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?