WebSocket connection to 'wss://12.34.56.78:8089/mqtt' failed: Unexpected response code: 400

707 views
Skip to first unread message

Jette Derriche

unread,
Feb 4, 2015, 4:08:39 AM2/4/15
to phon...@googlegroups.com
I am trying to implement a chat in a cordova/android hybrid app. But the project is currently stuck with this message:

WebSocket connection to 'wss://12.34.56.78:8089/mqtt' failed: Unexpected response code: 400 

** It works fine in:
Browser on laptop
Browser in emulator

** Does not work ind
App on emulator (same error as above)
App on device (same error as above)
Browser on device (timeout)

As far as I can Google, Android 4.4.2 webview should have support for websockets. There is no problems on the network, since the device is running on the same wifi as my laptop. But I am beginning to wonder if the port could be blocked in the webview?

** Client:
Samsung Galaxy S5
Android 4.4.2
Chrome 30.0 (in webview)
Cordova 3.6.3-0.2.13
Paho Mqtt JS 3.1

** Server
HiveMQ 2.2.0

Any ideas are much appreciated :-)

/Jette

Kerri Shotts

unread,
Feb 4, 2015, 10:18:56 AM2/4/15
to phon...@googlegroups.com
Some code might help us help you.

Jette Derriche

unread,
Feb 4, 2015, 5:25:17 PM2/4/15
to phon...@googlegroups.com
Since my previous post, I discovered that the client is actually connected in some way. The client is able to sent messages (the server receives them) but the connection is immediatly dropped. Therefore no messages are received by the client, and I have to reconnect the client every time it sends a message.

The error is displayed in the console upon client.connect(), but the "We are now connected..."-message still displays.

client = new Paho.MQTT.Client(EnvConfig.chatServer, EnvConfig.chatPort, connId);
console
.log("Trying to connect");

client
.connect({
  onSuccess
:function() {
    connected
= true;
    console
.log("We are now connected to HiveMQ");
 
},

  onFailure
:function(errObj) {
    connected
= false;

    console
.log("Cannot connect to HiveMQ:");
    console
.log("invocationContext = "+errObj.invocationContext);
    console
.log("errorCode = "+errObj.errorCode);
    console
.log("errorText = "+errObj.errorText);
 
},
  useSSL
:true,
  cleanSession
:false
});



Jette Derriche

unread,
Feb 5, 2015, 5:16:20 AM2/5/15
to phon...@googlegroups.com
The trouble seems to be solved... Apparently Paho does not write errors to the console, but keeps them internally in a buffer. The buffer revealed "undefined" errors... So it's all down to me being a newbie on this :-)

Bonus info for other newbies: You should look at Paho's starTrace(), stopTrace() and getTraceLog() functions :-)
Reply all
Reply to author
Forward
0 new messages