Closed YasserTahri closed 7 years ago
Hard to tell, probably you configured something wrongly on the HTTP/WebSocket layer.
ok, please can you tell me how i will make a correct config on the HTTP/WebSocket layer.
Thank you
how are you doing it right now?
my brocker.js
var mosca = require('mosca')
var ascoltatore = {
//using ascoltatore
type: 'mongo',
url: 'mongodb://localhost:27017/agg_mqtt',
pubsubCollection: 'ascoltatori',
mongo: {}
};
var moscaSettings = { backend: ascoltatore, http: { port: 3000, bundle: true, static: './' }, persistence: { factory: mosca.persistence.Mongo, url: 'mongodb://localhost:27017/agg_mqtt' } }; var server = new mosca.Server(moscaSettings); server.on('clientConnected', function(client) { console.log('client connected', client.id); }); server.on('subscribed', (topic, client) => { server.publish(message, client) })
// fired when a message is received server.on('published', function(packet, client) { console.log('Published', packet.payload); });
server.on('ready', setup);
// fired when the mqtt server is ready function setup() { console.log('Mosca server is up and running'); }
what's your code on the client?
that should work from the browser. Which browser are you using?
I have linked mqtt.js already exist in public folder in mosca to my html page my browser is : google chrome my MQTT web client :
var client = mqtt.connect(); var sub = client.subscribe("/myTopic"); client.on("message", function(topic, payload) { alert([topic, payload].join(": ")); client.end(); }); client.publish("/myTopic","test");
thx
WebSocket connection to 'ws://xxx.aggema.com/' failed: Error during WebSocket handshake: Unexpected response code: 200
are you serving this through NGINX? What's that domain name?
xxx.aggema.com/ : it's domaine of my web site with apache
The problem is apache. It does not support Websockets.
You need to use websockets. You can fire Mosca on another domain/port and connect it there.
i have used mqtt.js client , have you an idea about others web client mqtt
thx
it's a matter of infrastructure and protocol.
Great, i want to send a message from my web site to android client using mqtt protocol and mosca broker
@YasserTahri for same I created nodejs websocket bridge so anything published on webpage will be relay to mqtt and reverse.
also you can tweak mosca server to do both
Hi guys,
I need to make a push to send a message from my interface to android client, already i have installed mosca and using MQTT web client but when i want to publish i see a message in my console : "connection to 'ws://xxx.aggema.com/' failed: Error during WebSocket handshake: Unexpected response code: 200"