I am testing the MQTT server using the HiveMQ client but have also created a quick Pahoo webpage hack.
HiveMQ seems to work fine under Firefox but fails to MQTT connect under Chrome reporting 'Connect failed: AMQJS0007E Socket error:undefined'.
Wireshark shows that Chrome disconnects immediately after receiving the MQTT server's (well actually the HTTP server at this stage) Websocket upgrade response.
Throwing together a webpage using Paho Javascript MQTT client and Chrome console reports:
Code: Select all
mqttws31.js:982 WebSocket connection to 'ws://192.168.80.100/mqtt' failed: Error during WebSocket handshake: Sent non-empty 'Sec-WebSocket-Protocol' header but no response was received
Paho.MQTT.ClientImpl._doConnect @ mqttws31.js:982
Paho.MQTT.ClientImpl.connect @ mqttws31.js:852
Client.connect @ mqttws31.js:1809
There seems to be an issue with the ESP websocket server library?
EDIT: I tried the websocket echo server example. The following Javascript works within Chrome. Why would one upgrade work & not the other?
Code: Select all
function test_websocket()
{
if ("WebSocket" in window) {
//alert("WebSocket is supported by your Browser!");
// Let us open a web socket
var ws = new WebSocket("ws://192.168.0.48/ws");
ws.onopen = function() {
// Web Socket is connected, send data using send()
ws.send("Message to send");
alert("Message is sent...");
};
ws.onmessage = function (evt) {
var received_msg = evt.data;
alert("Message is received...'" + received_msg + "'");
};
ws.onclose = function() {
// websocket is closed.
alert("Connection is closed...");
};
} else {
// The browser doesn't support WebSocket
alert("WebSocket NOT supported by your Browser!");
}
}