secure-client.js 588 B

123456789101112131415161718192021222324
  1. 'use strict'
  2. var mqtt = require('../..')
  3. var path = require('path')
  4. var fs = require('fs')
  5. var KEY = fs.readFileSync(path.join(__dirname, '..', '..', 'test', 'helpers', 'tls-key.pem'))
  6. var CERT = fs.readFileSync(path.join(__dirname, '..', '..', 'test', 'helpers', 'tls-cert.pem'))
  7. var PORT = 8443
  8. var options = {
  9. port: PORT,
  10. key: KEY,
  11. cert: CERT,
  12. rejectUnauthorized: false
  13. }
  14. var client = mqtt.connect(options)
  15. client.subscribe('messages')
  16. client.publish('messages', 'Current time is: ' + new Date())
  17. client.on('message', function (topic, message) {
  18. console.log(message)
  19. })