Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [paho-dev] JS Client and Combined Packets

Hi Nick,

I just upgraded to the latest master.  It looks like it allows multiple messages, but it still constructs the messages incorrectly.  Specifically, the subarray calls in PUBLISH and SUBACK append the entire end of the byteArray instead of just until the end of the message.

Changing the calls to input.subarray(pos, endPos) fixes this problem.


On Mar 20, 2014 8:51 AM, "Elliot Morrison-Reed" <elliotmr@xxxxxxxxx> wrote:

Hi Nick,

I was working with the old master from before the merge, looked briefly through the commit logs and somehow the fix comment didn't register.  Just looked at it and it is similar to what I implemented.  I'll give it a shot with the new master today.  Thanks!


On Mar 20, 2014 1:16 AM, "Nicholas O'Leary" <nick.oleary@xxxxxxxxx> wrote:

Hi Elliot,

When did you grab the paho js client and from where?

We recently merged the develop branch to master which brings support for multiple (or partial) mqtt packets in each WS frame.


On 19 Mar 2014 18:15, "Elliot Morrison-Reed" <elliotmr@xxxxxxxxx> wrote:
Hello All,

I have been working a little project that involves connecting users behind an oppressive corporate firewall to an MQTT broker through a web browser.  Since WebSockets are essentially blocked, I ended up using node.js and in long-polling mode to simulate the WebSocket interface for the _javascript_ MQTT client.

Here is the abridged (but functional) version.

var net = require('net');
var engine = require('');
var http = require('http');

function sendToMosquitto (data, mosqConn) { mosqConn.write(data); }
function sendToSocket (data, engineSocket) { engineSocket.send(new Buffer(data)); }
function startMosqClient(engine_socket) {
    var mosq_client = new net.Socket();
    engine_socket.on('message', function (data) { sendToMosquitto(data, mosq_client); });
    mosq_client.on('data', function (data) {sendToSocket(data, engine_socket);});

var server = engine.attach(http.createServer().listen(80));
server.on('connection', function (engine_socket) { startMosqClient(engine_socket); });

In general it works, however I have run across an interesting issue with the _javascript_ client.

For some reason this app is combining many MQTT messages from the Mosquitto into a single "data received" event, this means when I forward them on to the _javascript_ client, it will also receive multiple messages at the same time.  It looks like the JS client is not equipped to handle this, as instead of looking at the length in the MQTT header it just appends everything else in the packet as whatever the final argument.

I made a quick fix in my copy of the client, however I don't know if it is only required because of the client replacing the WebSocket connection, or if this could also be a problem for people who are only using regular WebSockets.  I can submit a bug report and a patch suggestion to the Bug Tracker if the consensus is that it is a real bug.

From my side, I am quite happy with the setup except the bundling issue that I mentioned before.  Does anybody have an idea why I would be receiving many Mosquitto packets all together as a single receive with this setup?

Elliot Morrison-Reed

paho-dev mailing list

paho-dev mailing list

Back to the top