cans
cans

Reputation: 67

AEDES SERVER DOES NOT CONNECT TO CLIENT

I want to make a simple client server example with visual studio code. For my mqtt client instance, mosca didn't work. So I created a server with aedes. However, it is not possible to connect to client.js at the moment. I'm sure it's missing on the server side, but I'm not sure how to fix it. I'm very new to this. my codes are below.

Server;

const aedes = require('aedes')()
const server = require('net').createServer(aedes.handle)
const httpServer = require('http').createServer()
const ws = require('websocket-stream')
const port = 1883
const wsPort = 3000

server.listen(port, function () {
  console.log('server started and listening on port ', port)
})

ws.createServer({ server: httpServer }, aedes.handle)

httpServer.listen(wsPort, function () {
  console.log('websocket server listening on port ', wsPort)
})

Client;

var mqtt = require('mqtt');
var client = mqtt.connect('mqtt://192.168.43.40:1883');

client.subscribe('new-user');

client.on('connect', function() {
    console.log('connected!');

    client.publish('new-user', 'Cansu-' + Math.ceil(Math.random() * 10));
});

client.on('message', function(topic, message) {
    console.log(topic, ' : ', message.toString());
    client.end();
});

Thank You!!!

Upvotes: 1

Views: 592

Answers (0)

Related Questions