How to use the mqtt.createConnection function in mqtt

To help you get started, we’ve selected a few mqtt examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mcollina / mosca / test / server.js View on Github external
function buildClient(done, callback) {
    var client = mqtt.createConnection(settings.port, settings.host);

    client.once('error', done);
    client.stream.once('close', function() {
      done();
    });

    client.on("connected", function() {
      callback(client);
    });
  }
github mcollina / mosca / test / server.js View on Github external
function buildClient(instance, done, callback) {
    var client = mqtt.createConnection(instance.opts.port);

    client.once('error', done);
    client.stream.once('close', function() {
      done();
    });

    client.on("connected", function() {
      callback(client);
    });
  }
github node-red / node-red / packages / node_modules / @node-red / nodes / core / network / lib / mqtt.js View on Github external
MQTTClient.prototype.connect = function(options) {
   if (!this.connected) {
       var self = this;
       options = options||{};
       self.options = options;
       self.options.keepalive = options.keepalive||15;
       self.options.clean = self.options.clean||true;
       self.options.protocolId = 'MQIsdp';
       self.options.protocolVersion = 3;

       self.client = mqtt.createConnection(this.port,this.host,function(err,client) {
             if (err) {
                self.connected = false;
                clearInterval(self.watchdog);
                self.connectionError = true;
                //util.log('[mqtt] ['+self.uid+'] connection error 1 : '+inspect(err));
                self.emit('connectionlost',err);
                return;
             }
             client.on('close',function(e) {
                   //util.log('[mqtt] ['+self.uid+'] on close');
                   clearInterval(self.watchdog);
                   if (!self.connectionError) {
                       if (self.connected) {
                          self.connected = false;
                          self.emit('connectionlost',e);
                       } else {
github mcollina / ponte / benchmark / one-to-many / coap-to-mqtt.js View on Github external
, next = function() {
             if (receivers.length <= total) {
               mqtt.createConnection(1883, '127.0.0.1', created);
             }
           };
github mcollina / ponte / benchmark / many-to-one / mqtt-to-coap.js View on Github external
, next = function() {
             if (publishers.length < total) {
               mqtt.createConnection(1883, '127.0.0.1', created);
             }
           };
github mcollina / ponte / benchmark / many-to-one / mqtt-to-mqtt.js View on Github external
, next = function() {
             if (publishers.length < total) {
               mqtt.createConnection(1883, '127.0.0.1', created);
             }
           };
github mcollina / ponte / benchmark / one-to-many / http-to-mqtt.js View on Github external
, next = function() {
             if (receivers.length <= total) {
               mqtt.createConnection(1883, '127.0.0.1', created);
             }
           };
github mcollina / ponte / benchmark / one-to-many / mqtt-to-mqtt.js View on Github external
, next = function() {
             if (receivers.length <= total) {
               mqtt.createConnection(1883, '127.0.0.1', created);
             }
           };