mercredi 4 décembre 2019

Why do I use mqtt.js to connect to the local apache-apollo-1.7.1 server with frequent disconnections and reconnections?

var self = this
            self.logs.push('connect')
            var mqtt = require('mqtt')
            // #ifdef H5
            var client = mqtt.connect('ws://127.0.0.1:61623',{
                username:'admin',
                password:'password',
                clean:false,
                clientId:'mqttjs_' + Math.random().toString(16).substr(2, 8)
            })
            // #endif
            console.log(client);
            client.on('connect', function() {
                self.logs.push('on connect');
                client.subscribe('chat/general', function(err) {
                    console.log(err);
                    if (!err) {
                        self.logs.push(err)
                    }
                })
                client.subscribe('month', function(err) {
                    if (!err) {
                        client.publish('month','Friday');
                    }
                })
                client.publish('year','2019');
                client.publish('_bool',true);
            }).on('reconnect', function() {
                self.logs.push('on reconnect')
            })

this is my code,Why do I use mqtt.js to connect to the local apache-apollo-1.7.1 server with frequent disconnections and reconnections?Is it a server configuration problem?




Aucun commentaire:

Enregistrer un commentaire