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

[455 byte] By [Ahmad_Khana] at [2007-11-26 15:07:29]
# 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.

sjasjaa at 2007-7-8 8:57:32 > top of Java-index,Archived Forums,Socket Programming...
# 2
(a) As sjasja says, those methods don't do that. They just tell you what you have done with your own Socket.(b) The default keepalive interval is at least two hours.
ejpa at 2007-7-8 8:57:32 > top of Java-index,Archived Forums,Socket Programming...