socketio / engine.io-client-java

Engine.IO Client Library for Java
http://socketio.github.io/engine.io-client-java
Other
360 stars 167 forks source link

fixe added onClose #69

Closed eckovation closed 8 years ago

nkzawa commented 8 years ago

Thanks for your PR! Am I correct you confirmed this PR fixes NullPointerException https://github.com/socketio/socket.io-client-java/issues/343 ?

shaacker commented 8 years ago

In my change, I did the call to close() intentionally, because it checks the ready state and ALSO calls onClose() which updates the internal state properly.

public Transport close() {
    EventThread.exec(new Runnable() {
        @Override
        public void run() {
            if (Transport.this.readyState == ReadyState.OPENING || Transport.this.readyState == ReadyState.OPEN) {
                Transport.this.doClose();
                Transport.this.onClose();
            }
        }
    });
    return this;
}

How does this change improve the situation? I imagine it would leave the internal readyState still at ReadyState.OPEN which would then mess with reconnect attempts.

@nkzawa Please correct me if I'm wrong.

nkzawa commented 8 years ago

@chendrak I expect the onClose listener of websocket would be called in this case anyway. (https://github.com/socketio/engine.io-client-java/blob/master/src/main/java/io/socket/engineio/client/transports/WebSocket.java#L136) If it's true, we wouldn't need to change the ready state here IMO.

shaacker commented 8 years ago

@nkzawa Ah, perfect. In that case the close() might be the better option.

eckovation commented 8 years ago

@nkzawa @chendrak I just checked the the library by compiling it into a real app, and i can confirm that, this fix, fixes the issue.

I tried, regenerating it through following steps, Put the debugger on Line#345 (Socket.java) and before it executes that line, disconnect the internet. And after that it did not crash on Line#346 (Socket.java) as it used to, when we close the transport using close()

So it seems, doClose() is indeed working.

Can you guys please share your thoughts on this?

eckovation commented 8 years ago

@nkzawa if its all good, can you merge it?

nkzawa commented 8 years ago

@eckovation thank you!