Java client with websocket : Invalid Frame : Opcode 15 error [message #1724318] |
Tue, 23 February 2016 07:16 |
Vineet Dixit Messages: 3 Registered: February 2016 |
Junior Member |
|
|
Hello,
I am using the development build org.eclipse.paho.client.mqttv3-1.0.3-SNAPSHOT.jar to connect to a Mosquitto 1.4.8 using wss://
.
The client disconnects due to "Invalid Frame" error pasted below.
Publishing at: 2016-02-22 22:59:03.496 to topic "mqtt/demo" qos 2
WebSocketReceiver.java : run(): Exception Occured.
java.io.IOException: Invalid Frame: Opcode: 15
at org.eclipse.paho.client.mqttv3.internal.websocket.WebSocketFrame.<init>(WebSocketFrame.java:187)
at org.eclipse.paho.client.mqttv3.internal.websocket.WebSocketReceiver.run(WebSocketReceiver.java:98)
at java.lang.Thread.run(Thread.java:745)
Disconnected
This happens over ws:// as well. Same client can connect to Mosca broker just fine, both over ws:// and wss://. Similarly, other clients (iOS, Node.js, C) can connect to Mosquitto 1.4.8 just fine, both over ws:// and wss://
I ran wireshark to see if Mosquitto was sending a frame with opcode 15, but I couldn't locate any such frame.
I still haven't looked into the websocket implementation, but thought someone might be able to shed light on this error.
Thx,
Vineet
|
|
|
Re: Java client with websocket : Invalid Frame : Opcode 15 error [message #1724444 is a reply to message #1724318] |
Wed, 24 February 2016 01:33 |
Vineet Dixit Messages: 3 Registered: February 2016 |
Junior Member |
|
|
I did further testing and found out that the client closes TCP connection after exchanging some data with the broker. It's a graceful connection closure with complete FIN/ACK sequence. After a FIN/ACK from the broker the InputStream to reach EOF. Websocket code is not correctly handling this case.
In WebSocketReceiver.java, the input.available() ALWAYS returns zero. At first I thought this was a reliable method to test if there was a data available to be read, but the Java documentation says this may not be so.
93 while (running && (input != null)) {
94 try {
95 //@TRACE 852=network read message
96 log.fine(CLASS_NAME, methodName, "852");
97 receiving = input.available() > 0;
98 System.out.println("input.available = " + input.available());
99 WebSocketFrame incomingFrame = new WebSocketFrame(input);
Then WebSocketFrame reads a byte from the stream and directly starts to decode the opcode and fin flag. In case of server close, input.read() returns -1 (0xFF). This causes the opcode to become 15.
public WebSocketFrame(InputStream input) throws IOException {
133 byte firstByte = (byte) input.read();
134
135
136 /*
137 * Peer has closed TCP connection
138 */
139 if (firstByte == -1) {
140 System.out.println("TCP FIN is received from the remote");
141 }
142
I still have to look deeper, but it does appear that the websockets code and even the normal TCP code path is not handling graceful closures from the server correctly. Similarly, the code should be checking for abnormal connection terminations due to TCP RST.
Am I reading this correctly?
[Updated on: Wed, 24 February 2016 01:37] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03525 seconds