The examples in the Networking lesson did not close any of the input
streams, the output streams, the readers, or the writers.  I have some
questions about that:

1) Is it normal to NOT close those objects?
2) When should we explicitly close a stream, a reader, or a writer --
and when is OK not to?  [Does it depend on the specific class, or
maybe how long before the program exits and releases everything
anyways?]
3) If I do close a reader that's wrapper around an input stream, does
the input stream automatically get closed as well?  [Is the same true
for a writer and an output stream?]

Also, I'd like to share an observation with the group.  I noticed that
if you do not flush the writer before closing the socket, then the
unflushed data will not be written to the socket.  Be careful with
that.  Here's a sample of broken code:

Socket client = server.accept();
PrintWriter out = new PrintWriter(client.getOutputStream()); // no
auto-flush
out.println("poop, but don't flush"); // put the message in the buffer
client.close(); // failure: the message is never delivered

-- 
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/javaprogrammingwithpassion?hl=en

Reply via email to