How to set KeepAlive value
I have a couple of questions.
1. For one of my applications I am unable to detect when the socketi s closed from the other end Socket.isConnected returns true, isClosed is false and isBound returns true. What can be the reason for this ?
2. In order to solve the first issue I set the setKeepAlive to true but I dont know the frequency of keep alive. How to set the frequency of sending Keep alive packets.
Many thanks
Ahmad
# 1
1. That's the way TCP/IP works. You can't use those functions to find out whether the other end has closed connection. Instead, write to the socket and get an IOException, or read and get an end of stream indication (-1, null, IOException, etc, depending on what method of reading you use.)
2. Can't set keepalive interval using the socket API. Operating systems don't support that. You operating system might have a setting for it (e.g. a registry setting in Windows, ndd in Solaris), but it's likely to be global and affect all applications. It's unlikely you should mess with that. Implement an application protocol level heartbeat instead.