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

MQTT over WS with Mosca+Express  #802

@kocil

Description

@kocil

Dear sir.
I'm trying to use mqtt over web socket, as described
https://github.com/mcollina/mosca/wiki/MQTT-over-Websockets

The client is running on Chrome.
Using the embedded MOSCA, it worked well.

But using the MQTT.js Browserify Bundle, it did not work.
My server side initialization is as follow:

//=============================================
// Mosca & Express initialization
var mosca = require("mosca");
var broker = new mosca.Server({});
var express = require("express");
var http = require("http");
var app = express()
var srv = http.createServer(app)

broker.attachHttpServer(srv);

// mqtt.js from node_modules/mosca/public was copied to the public folder
// thus the web root is the default public
app.use(express.static('public'));

app.listen(3000, () => console.log('WebApp listening on port 3000!'));
//=====================================

The express worked, it can serve the static HTML as well as the API.
However the MQTT client was failed with the following error:
WebSocket connection to 'ws://192.168.100.5:3000/' failed: Error during WebSocket handshake: Unexpected response code: 200

Please help. Thank you in advance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions