diff --git a/lib/connect/tls.js b/lib/connect/tls.js index aac296666..ccf3731cd 100644 --- a/lib/connect/tls.js +++ b/lib/connect/tls.js @@ -1,12 +1,16 @@ 'use strict' var tls = require('tls') +var net = require('net') var debug = require('debug')('mqttjs:tls') function buildBuilder (mqttClient, opts) { var connection opts.port = opts.port || 8883 opts.host = opts.hostname || opts.host || 'localhost' - opts.servername = opts.host + + if(net.isIP(opts.host) === 0){ + opts.servername = opts.host + } opts.rejectUnauthorized = opts.rejectUnauthorized !== false