Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Paho » Java client with websocket : Invalid Frame : Opcode 15 error
Java client with websocket : Invalid Frame : Opcode 15 error [message #1724318] Tue, 23 February 2016 07:16 Go to next message
Vineet Dixit is currently offline Vineet DixitFriend
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 Go to previous messageGo to next message
Vineet Dixit is currently offline Vineet DixitFriend
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

Re: Java client with websocket : Invalid Frame : Opcode 15 error [message #1724812 is a reply to message #1724444] Fri, 26 February 2016 09:42 Go to previous messageGo to next message
James Sutton is currently offline James SuttonFriend
Messages: 69
Registered: July 2015
Member
Hi,

It certainly looks like there is a problem there, could you tell me how to re-create this? From your log it looks like you're attempting to publish a message to a topic at QoS 2 which is followed by the exception but I've been unable to recreate this with my code and the broker at iot.eclipse.org.

Once I've confirmed that this is repeatable I'll open an issue and see if we can find a resolution.

Thanks - J
Re: Java client with websocket : Invalid Frame : Opcode 15 error [message #1724906 is a reply to message #1724318] Fri, 26 February 2016 23:36 Go to previous message
Vineet Dixit is currently offline Vineet DixitFriend
Messages: 3
Registered: February 2016
Junior Member
Hi James,

The most reliable way to reproduce this is to call connect method immediately followed by disconnect method.

client.connect()
client.disconnect

I modified the publish method in Sample.java by commenting out the client.publish() call, but left rest of the code unmodified. Hence it's picking up the QoS level 2.

java Sample -b <broker-ip> -p 8080 -v false -t "mqtt/demo"

I have opened a bug on Bugzilla https://bugs.eclipse.org/bugs/show_bug.cgi?id=488345

HTH,
Vineet

[Updated on: Fri, 26 February 2016 23:41]

Report message to a moderator

Previous Topic:Paho java client - cannot create more than 5000 connections
Next Topic:Error when running Paho MQTT C Client in Windows for x64
Goto Forum:
  


Current Time: Thu Sep 20 21:03:03 GMT 2018

Powered by FUDForum. Page generated in 0.02111 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top