Closed YasserTahri closed 7 years ago
How does that fits into Mosca? Can you explain your architecture a bit more?
first , i have installed mosca on my windows server and after i added my broker in mosca and i'm trying to send notification message from my web client interface to ANDROID APP CLIENT
my architecture is : Browser chrome or fire (UI) == send message===> mosca ===> android application My Broker :
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'); }
Part web Client :
can you help me how i can use the best solution to send message from my web client to android app
thank you
what's not working?
when i tryto select message and clic into button to send my selected message to android app , in other word no notification is happened in android app also in my broker
Does it work with a standard MQTT client?
Have you tried putting a full URL inside mqtt.connect()
?
already i have used this MQTT client : https://github.com/mqttjs/MQTT.js
and about mqtt.connect() already i made full URL of my server
Code in my html page :
also when i make full URL always i see this error message :
' failed: Error during WebSocket handshake: Unexpected response code: 200
In your script, you are not passing a full URL to mqtt.connet()
. It should be something like mqtt.connect('ws://{YOURDOMAIN/IP}')
,
message in console : WebSocket connection to 'ws://46.21.205.50/' failed: Error during WebSocket handshake: Unexpected response code: 200
from your example, you are running Mosca on port 3000, not 80.
i changed port 3000 to 80 but same problem :
WebSocket connection to 'ws://46.21.205.50/' failed: Error during WebSocket handshake: Unexpected response code: 200
you can't 80, as you are probably serving something else there, like your index.html. You need to keep that as 3000, and connect to mqtt.connect('ws://46.21.205.50:3000')
.
yes i have done mqtt.connect('ws://46.21.205.50:3000') but unfortunetely the same problem
message error : WebSocket connection to 'ws://46.21.205.50:3000/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
you Mosca instance is not really running and/or exposed at that port.
when i run subscribe and publish on server by command it works but the problem when i run it on web client
those are served on two separate ports. What is serving your web client?
mosca port http : 3000 web client 80 MQTT port :1883
so, you need to connect to port 3000 with mqtt.connect()
.
WebSocket connection to 'ws://46.21.205.50:3000/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
are you sure that port 3000 is open on that host? Is that host a server?
port 3000 opened and IP is the adress of my server
@mcollina can you tell me about the best architecture and tools that i can use
because i think it's a problem in my architecture
thank you
very likely, but I have little time, and this is Mosca issue tracker.
already port is verified that it's opened
Hi guys,
i need help, i faced a problem to send notification from my web browser to android client !
can you explain with simple method for sending a notification message from web client
thank you in advance