Is there any way to set socket level options (like SO_KEEPALIVE) for a JDK stdlib HttpUrlConnection
? I'm trying to figure out a way to GET HTTP requests that doesn't fall victim to occasional "hanging" connections (which seem to occur because of network packet loss every so often). A more robust HTTP client. I know there is the setReadTimeout
method but I am trying to find something to nudge the TCP stream back into life, instead of just aborting it, as the read timeout seems to. Or at least report that the connection failure has occurred instead of hanging forever on a read. But that also allows the read to come back "whenever it wants to" assuming the connection is "still active."
With some examination it appears that the default for SO_KEEPALIVE is "off" for both the C layer and Java level sockets.