How can a socket be both connected and closed?

Viewed 17021

I'm using a Java socket client. In a case where the server is still connected to my client but it does not send a response to my message - I eventually get a read time out exception.

In that case I want to test to see if I should reconnect my socket or just keep it an re-use it.

I use this condition:

if (!socket.isConnected() || socket.isClosed() || !socket.isBound()) {
    try {
        socket.close();
    } catch (IOException e1) {
    }
    // Wait on a new connection
    socket = connectSocket(.....);
}

But I always seem to reconnect. When I log the values of the Boolean properties I see this:

connected: true closed: true bound: true

How can it be connected and closed?

TIA

1 Answers
Related