Open Swapnilchavan18 opened 7 years ago
How have you configured your NGINX?
On your local machine, inside this.client = mqtt.connect('mqtt://www.test.com', options);
use mqtt://SERVER_URL
.
After that publish a message on a specific topic from the server, like below,
var message = {
topic: '/myPersonalTopic',
payload: 'abcde',
qos: 0,
retain: false
};
server.publish(message, function () {
console.log('done!');
});
And then connect client, and subscribe to a topic in which message is published earlier, like below
client.on('connect', function () {
client.subscribe('/myPersonalTopic', function (err) {
if (!err) {
client.publish('/myPersonalTopic', 'Message Received')
}
})
})
I have create mosca server with simple code server.js as below, I run it as nodejs app via node server.js I have running website for ex test.com with nginx. How to connect to mosca from client? When I try to connect it takes long time of 1m and request times out.
Server.js code is as below ` var mosca = require('mosca')
and with another node app which I run on local machine I have code as below.
` var mqtt = require('mqtt'); var options = { port: 1883, host: 'mqtt://www.test.com', keepalive: 60, reconnectPeriod: 1000, protocolId: 'MQIsdp', protocolVersion: 3, clean: true, encoding: 'utf8' }; this.client = mqtt.connect('mqtt://www.test.com', options);
It doesnt connect and gets timed out.