1

i'm new to mqtt messaging client in javascript. can any one say that this code is written in client side or server side.

client = new Messaging.Client(location.hostname, Number(location.port), "clientId");
client.onConnectionLost = onConnectionLost;
client.onMessageArrived = onMessageArrived;
client.connect({onSuccess:onConnect});
function onConnect() {
    // Once a connection has been made, make a subscription and send a message.
    console.log("onConnect");
    client.subscribe("/World");
    message = new Messaging.Message("Hello");
    message.destinationName = "/World";
    client.send(message);
};
function onConnectionLost(responseObject) {
    if (responseObject.errorCode !== 0)
        console.log("onConnectionLost:"+responseObject.errorMessage);
};
function onMessageArrived(message) {
    console.log("onMessageArrived:"+message.payloadString);
    client.disconnect();
};

can anyone write a server code in nodejs,javascript and socket. please give it. in advance thanks.

2 Answers 2

1

The handler functions suggest that it is the client side.

PS: If you don't mind, could you tell us which library this is? Thanks.

Sign up to request clarification or add additional context in comments.

2 Comments

can you please suggest the server side code in mqtt server. This is a nodejs with javscript and socket.io
I have done an mqtt nodejs app using the below as reference. Use npm to install this package github.com/adamvr/MQTT.js
0

This is using the Eclipse Paho javascript client, http://eclipse.org/paho, which is for use within the browser.

1 Comment

Can you please suggest me how to write server code with mqtt broker and javascript socket.io nodejs

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.