Can someone explain the following behavior in Java sockets:
The general idea is this:
It is probably because calling the close() method of PrintWriter is tracing back through the hierarchy and calling the close() method of the SocketOutputStream as well. As part of the close() method for the SocketOutputStream it also calls the close() method for the Socket as well, which would in term close the SocketInputStream as well. Calling the shutdownOutput() function instead sends any previously written data followed by TCP's normal connection termination sequence. It then disables the output stream.