Closed mfsi-ankitb closed 8 years ago
Thank you for your suggestion. I'm busy now but will surely look into this later. Thanks!
It seems that the issue happens when the WebSocket server closes the WebSocket connection without sending a close frame (other cases are actually "insufficient data"). If it is the case, it means that the WebSocket server does not comply with RFC 6455. What WebSocket server are you using?
Server is written in node.js
My guess is that the behavior is caused by a wrong implementation on the server side. But, it may be doable to add an option to WebSocket
class to allow an empty frame and close the connection without raising an exception. However, the modification would not be so simple as you may guess because it would be an exceptional behavior against the closing handshake and of course would be a violation against the specification. If you want to such an option, please let me know.
I found that a certain WebSocket server implementation (echo.websocket.org
) closes a WebSocket connection without performing a closing handshake if a WebSocket client does not immediately respond to a PING frame sent from the server.
Disconnection without a closing handshake causes nv-websocket-client
to raise the error of "The end of the stream has reached unexpectedly."
Therefore, I improved the implementation to process PING & PONG frames immediately. After the improvement, the error has not been observed at least in my environment.
Please use the new version 1.16
. It includes the improvement.
Thanks for updating, I will surely try and tell my experience
Released the version 1.29 for this issue and #63. 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.
I got an issue and debugged it "socket was getting disconnected due to the fact the library is trying to read incoming frame which might not have any bytes available".
Easy proposed solution: Following lines
in
WebSocketInputStream.java
with inreadBytes()
method at line 141 should be commented out.