The half-close provides the ability for one end of a socket connection to terminate its output while still receiving data from the other end.
Here is a typical situation. Suppose you transmit data to the server but you don’t know at the outset how much data you have. With a file, you’d just close the file at the end of the data. However, if you close a socket, you immediately disconnect from the server and cannot read the response.
The half-close overcomes this problem. You can close the output stream of a socket, thereby indicating to the server the end of the requested data, but keep the input stream open.
The client side looks like this:
Socket socket = new Socket(host, port); Scanner in = new ...