Skip to content
This repository has been archived by the owner on Feb 11, 2020. It is now read-only.

mqtt over websocket and vanilla websocket cohabitat #605

Closed
namgk opened this issue Feb 13, 2017 · 3 comments
Closed

mqtt over websocket and vanilla websocket cohabitat #605

namgk opened this issue Feb 13, 2017 · 3 comments

Comments

@namgk
Copy link
Contributor

namgk commented Feb 13, 2017

Hi there,

It seems that currently you cannot serve one http server with 2 websocket connections, one for vanilla ws and one for mqtt over ws.

What I mean by this:

const server = http.createServer();

const wss = new ws.Server({
  server:server,
  path:'/test',
  perMessageDeflate: false
})

var mqttServ = new mosca.Server({})
mqttServ.attachHttpServer(server);

When you have this setting, all ws clients cannot connect and throwing "Error: reserved fields must be empty". I guess the mosca mqtt server is interfering with the vanilla ws connection.

Indeed, when I change the following line to add a path to the mqtt over ws, it works like a charm:

https://github.com/mcollina/mosca/blob/ab4b35dc3bf27f224af4db244c1db02bd1620d4b/lib/server.js#L615

Server.prototype.attachHttpServer = function(server) {
  var that = this;
  ws.createServer({ server: server, path: '/mqttws' }, function(stream) {
    var conn = new Connection(stream);
    new Client(conn, that);
  });
};

The client would connect seemlessly using:

var client = mqtt.connect('ws://localhost:3333/mqttws');
@mcollina
Copy link
Collaborator

can you please send a PR, adding a path  option to attachHttpServer? So we can maintain the current behavior, and support also your use-case.

@namgk
Copy link
Contributor Author

namgk commented Feb 13, 2017

I'd like to, but there is a design decision, either we hard coded the path there or we have to change the attachHttpServer API to include the path configuration.

What's your thought?

@mcollina
Copy link
Collaborator

attachHttpServer can have the path  as an optional parameter.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants