This is a rather old question, but since I ran into the same problem, I wanted to share my solution. Basically, what I do is listening for a SocketTimeoutException
exception, and if it occurs, I set a boolean isConnected = false
. Once I start receiving statuses again, I set that boolean back to isConnected = true
. It is not the prettiest solution, but it works. Here my code for the Listener:
private StatusListener createListener() {
return new StatusListener() {
@Override
public void onStatus( Status tweet ) {
if (!isConnected)
isConnected = true;
doSomething(tweet);
}
( ... ) // Other @Override functions
@Override
public void onException( Exception ex ) {
if ( ( ex instanceof SocketTimeoutException ) && isConnected ) {
handleConnectionLoss();
isConnected = false;
} else {
System.err.println(ex);
}
}
};
}