Friday, February 23, 2024
 Popular · Latest · Hot · Upcoming
rated 0 times [  84] [ 7]  / answers: 1 / hits: 7001  / 9 Years ago, fri, january 2, 2015, 12:00:00

I am trying simple websocket based MQTT client and having Uncaught ReferenceError: Messaging is not defined error on console of Chrome.

<!DOCTYPE html>

<script src=mqttws31.js type=text/javascript charset=utf-8 async defer></script>

<script type=text/javascript>

var client;
var form = document.getElementById(tutorial);

function doConnect() {
var wsbroker =; //mqtt websocket enabled broker
var wsport = 80 // port for above

var client = new Messaging.Client(wsbroker, wsport,
myclientid_ + parseInt(Math.random() * 100, 10));
client.onConnect = onConnect;
client.onMessageArrived = onMessageArrived;
client.onConnectionLost = onConnectionLost;

function doSubscribe() {

function doSend() {
message = new Messaging.Message(Hello);
message.destinationName = /World;

function doDisconnect() {

// Web Messaging API callbacks

function onConnect() {
var form = document.getElementById(example);
form.connected.checked= true;

function onConnectionLost(responseObject) {
var form = document.getElementById(example);
form.connected.checked= false;
if (responseObject.errorCode !== 0)

function onMessageArrived(message) {
var form = document.getElementById(example);
form.receiveMsg.value = message.payloadString;


<h1>Example Web Messaging web page.</h1>
<form id=example>
<legend id=Connect > Connect </legend>
Make a connection to the server, and set up a call back used if a
message arrives for this client.
<input type=button value=Connect onClick=doConnect(this.form) name=Connect/>
<input type=checkbox name=connected disabled=disabled/>

<legend id=Subscribe > Subscribe </legend>
Make a subscription to topic /World.
<br> <input type=button value=Subscribe onClick=doSubscribe(this.form)/>

<legend id=Send > Send </legend>
Create a Message object containing the word Hello and then publish it at
the server.
<input type=button value=Send onClick=doSend(this.form)/>

<legend id=Receive > Receive </legend>
A copy of the published Message is received in the callback we created earlier.
<textarea name=receiveMsg rows=1 cols=40 disabled=disabled></textarea>

<legend id=Disconnect > Disconnect </legend>
Now disconnect this client from the server.
<br> <input type=button value=Disconnect onClick=doDisconnect()/>
</html -->

ERROR is on line var client = new Messaging.Client(wsbroker, wsport,

Error os Uncaught ReferenceError: Messaging is not defined

The java Script is from

Please suggest any solution...

More From » websocket


You are using an old example, the package name has changed it's not Messaging anymore it should be:

var client = new Paho.MQTT.Client(wsbroker, wsport,
myclientid_ + parseInt(Math.random() * 100, 10));

Also the port number for is 8080 not 80

[#40288] Wednesday, December 31, 2014, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.

Total Points: 694
Total Questions: 85
Total Answers: 103

Location: Somalia
Member since Mon, Feb 27, 2023
1 Year ago