Closed umesh0492 closed 8 years ago
@umesh0492 This may be a problem in this WebSocket library, but basically, this problem happens when a WebSocket server closes a WebSocket connection without performing a closing handshake (RFC 6455, 7. Closing the Connection). Please see also #12 .
@TakahikoKawasaki Would a network interruption cause the same issue? Is there any way I can detect if the server doesn't perform proper closing handshake or there is actually network interruption which causes this error ?
@TakahikoKawasaki i am sending the close frame to server when a connection close.
@l1f3l10n Network interruption will raise a WebSocketException
and your WebSocketListener
can detect it. In some cases, however, underlying systems such as Android do not report network disconnection to upper layers. In such a case, WebSocket library cannot detect the issue. See also my second comment in #55 .
@TakahikoKawasaki Saw your solution in other post. Thanks for your reply.
@umesh0492 The spec (RFC 6455) says both a client and a server can initiate a closing handshake by sending a close frame and the opposite which receives a close frame must send back a close frame to the initiating sender. I'm wondering whether your WebSocket server sends back a close frame.
One improvement idea is to treat an empty frame in a graceful way instead of raising an WebSocketException
, but I'm not so sure it is a good option. If I had to implement it, I would add a flag to enable/disable the feature. (But adding the feature is not a simple task.)
I am facing same issue in particular android device(Micro max Yu Yuphoria Yu5010A ) not in every device , is there any solution for this.
@rajashekarvys Hmm... It seems I should modify the implementation to work around this issue. Please give me some time.
Okay thank you
Released the version 1.29 for this issue and #12. Below is "Missing Close Frame" section added to README.md
. Note that "missing close frame" is not regarded as an error by default (but triggers closing handshake).
Some server implementations close a WebSocket connection without sending a close frame to a client in some cases. Strictly speaking, this is a violation against the specification (RFC 6455). However, this library has allowed the behavior by default since the version 1.29. Even if the end of the input stream of a WebSocket connection were reached without a close frame being received, it would trigger neither onError
method nor onFrameError
method of WebSocketListener
. If you want to make a WebSocket
instance report an error in the case, pass false
to setMissingCloseFrameAllowed
method.
// Make this library report an error when the end of the input stream
// of the WebSocket connection is reached before a close frame is read.
ws.setMissingCloseFrameAllowed(false);
If you find bugs in the implementation for "Missing Close Frame", please let me know.
Non-fatal Exception: com.neovisionaries.ws.client.WebSocketException: The end of the stream has been reached unexpectedly. at com.neovisionaries.ws.client.WebSocketInputStream.readBytes(WebSocketInputStream.java:153) at com.neovisionaries.ws.client.WebSocketInputStream.readFrame(WebSocketInputStream.java:44) at com.neovisionaries.ws.client.ReadingThread.readFrame(ReadingThread.java:334) at com.neovisionaries.ws.client.ReadingThread.main(ReadingThread.java:100) at com.neovisionaries.ws.client.ReadingThread.run(ReadingThread.java:65)