Wrong return from java.net.Socket.isConnected()
Hi all,
I use javax.net.ssl package to transport some bytes over tcp. That works fine. But i m checking the connection before sending something from the server to the client and vice versa and that causes some problems. When i check the Socket-Connection before connecting it, i got:
isConnected() -> false
isBound() -> false
isClosed() ->true
after connecting i got:
isConnected() ->true
isBound() ->true
isClosed() ->false
when the opposit side closes the connection I still get:
isConnected() -> true
isBound() ->true
isClosed->false
but when i try to access the connection i get:
"Connection has been shutdown: javax.net.ssl.SSLException: java.net.SocketException: Connection reset" .
Why stays isConnected() true even if there is no more connection? Why stays isClosed() false even when there is no more open connection? Is this the correct behauviour or should I get something else?
Greetings
Jugan
[1041 byte] By [
Jugana] at [2007-10-3 4:44:37]

> Why stays isConnected() true even if there is no more
> connection? Why stays isClosed() false even when
> there is no more open connection?
That's how the APIs are defined. Both of them only tell you whether you have carried out the corresponding operation on the specified Socket. They don't tell you anything about the state of the socket. See the Javadoc:
isConnected: 'Returns:
true if the socket successfuly connected to a server'
isClosed(): 'Returns:
true if the socket has been closed'
> Is this the correct behaviour
Yes.
> or should I get something else?
Yes. You can tell if the other end has closed its socket by reading an EOF or getting a SocketException when reading or writing. TCP/IP doesn't have any additional state about the connection, just the success or failure of I/O.
ejpa at 2007-7-14 22:48:48 >

Okay, in this case it is all about the wording. I read this doc's like:
isConnected() Returns True if the socket is 'currently' connected and not has been connected somewhen. So the difference is that I thought these methods would deliver actual state information and not a 'historic' protocol.
Thanks for your help!
Greetings
Jugan
Jugana at 2007-7-14 22:48:48 >
