Search code examples
network-programmingtcpnio

Why do we need a half-close socket?


According to this blog, it seems half open connection is what we want to avoid.

So why does Java still provides the facility to make a socket half close?


Solution

  • According to this blog, it seems half open connection is what we want to avoid.

    This author of the blog explicitly notes that he does not talk about deliberately half-closed connections but about half-open connections which are caused by intermediate devices like routers which drop the connection state after some timeout.

    So why does Java still provides the facility to make a socket half close?

    Because there are useful? Half-close just means that no more data will be send on the socket but it will still be able to receive data. This kind of behavior is actually useful for various situations where the client sends only a request and receives a response because it can be used to indicate the end of the request to the peer.