moscajs / mosca

MQTT broker as a module
mosca.io
3.2k stars 508 forks source link

Error: listen EADDRINUSE :::1883 #598

Closed ghost closed 7 years ago

ghost commented 7 years ago

If I run the example code from the website locally, I get the error Error: listen EADDRINUSE :::1883 but sudo ss -lptn 'sport = :1883' does not show anything on that port.

The code I use comes from https://github.com/mcollina/mosca/wiki/Mosca-basic-usage#lets-put-it-all-together-now

Any idea?

ghost commented 7 years ago

More complete output for the problem:

fsch@leopold: /[...]/moscatest$ sudo lsof -n -i :1883
fsch@leopold: /[...]/moscatest$ sudo netstat -nlp | grep :1883
fsch@leopold: /[...]/moscatest$ sudo ss -lptn 'sport = :1883'
State       Recv-Q Send-Q                 Local Address:Port             Peer Address:Port
fsch@leopold: /[...]/moscatest$ cat index.js
var http     = require('http')
  , httpServ = http.createServer()
  , mosca    = require('mosca')
  , mqttServ = new mosca.Server({});

mqttServ.attachHttpServer(httpServ);

httpServ.listen(3000);

var ascoltatore = {
  //using ascoltatore
  type: 'mongo',
  url: 'mongodb://localhost:27017/mqtt',
  pubsubCollection: 'ascoltatori',
  mongo: {}
};

var moscaSettings = {
  port: 1883,
  backend: ascoltatore,
  persistence: {
    factory: mosca.persistence.Mongo,
    url: 'mongodb://localhost:27017/mqtt'
  }
};

var server = new mosca.Server(moscaSettings);
server.on('ready', setup);

server.on('clientConnected', function(client) {
    console.log('client connected', client.id);
});

// fired when a message is received
server.on('published', function(packet, client) {
  console.log('Published', packet.payload);
});

// fired when the mqtt server is ready
function setup() {
  console.log('Mosca server is up and running')
}

fsch@leopold: /[...]/moscatest$ node index.js
events.js:141
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRINUSE :::1883
    at Object.exports._errnoException (util.js:870:11)
    at exports._exceptionWithHostPort (util.js:893:20)
    at Server._listen2 (net.js:1237:14)
    at listen (net.js:1273:10)
    at net.js:1382:9
    at nextTickCallbackWith3Args (node.js:452:9)
    at process._tickCallback (node.js:358:17)
ghost commented 7 years ago

Tiny bit more info: it works fine on port 1884.

mcollina commented 7 years ago

@fschwarzer there is something else listening in port 1883, usually RabbitMQ or Mosquitto

sihemhssine commented 6 years ago

It may be because the address you are trying to bind the server to is in use. Try another port or close the program using that port.