eclipse / paho.mqtt.javascript

paho.mqtt.javascript
Other
1.15k stars 467 forks source link

Sent non-empty 'Sec-WebSocket-Protocol' header but no response was received #82

Closed der-Chris closed 7 years ago

der-Chris commented 8 years ago

I'm using the Paho MQTT-Client with Apache Cordova to Connect to the Moquette MQTT-Broker in Java.

I'm working on this project for for a while now and now I am trying to connect via the "wss" protocol with an self signed certificate.

With the Client running in the Browser everything works as expected. But running on the Android Emulator I'm getting this error: "WebSocket connection to 'wss://10.10.10.154:8083/' failed: Error during WebSocket handshake: Sent non-empty 'Sec-WebSocket-Protocol' header but no response was received", source: file:///android_asset/www/plugins/cordova-plugin-websocket/www/websocket.js (162) While investigating I found this issue with moquette https://github.com/andsel/moquette/issues/90

So I tried changing the Line this.socket = new WebSocket(wsurl, ["mqtt"]); to this.socket = new WebSocket(wsurl, ["mqttv3.1.1"]);

Now it works as expected in the Browser and in Cordova with Android. I am not shure, if this would be a valid change, if the Problem is the Moquette MQTT Broker or the if the Paho Client is responsible.

jpwsutton commented 8 years ago

Hi,

The official subprotocol identifier for mqtt over websockets is 'mqtt', changing it to mqtt3.1.1 would be incorrect, so I think the bug is in moquette.

http://www.iana.org/assignments/websocket/websocket.xhtml http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/csprd02/mqtt-v3.1.1-csprd02.html#_Toc385349863