Mqttnet: WebSocket doesn't support

Created on 11 Feb 2020  路  10Comments  路  Source: chkr1011/MQTTnet

I am using .NET Core 3.1 and MQTTnet 3.0.8 and MQTTnet.AspCore 3.0.8 for my broker service. It's works fine when a client connect with mqtt protocol from MQTT.fx or .NET client; but whenever a request come from browser using ws protocol its seems like this


My .NET broker configuration

startup.cs


program.cs


I saw this Issue 390 conversation but nothing found useful for me.

Most helpful comment

It works. Thanks man

All 10 comments

// this maps the websocket to an mqtt endpoint
app.UseMqttEndpoint();

@JanEggers I used this, but result is same.

.NET Server Side
```c#
// websocket mapping
app.UseMqttEndpoint();

as by default `.NET` websocket mapping path is `/mqtt`

`JS Client Side`
```js
var client = MQTT.connect('mqtt://localhost:1883/mqtt');

yeah the client should be

var client = MQTT.connect('ws://localhost:5000/mqtt');

as the webservice runns in the http pipeline not on the mqtt port

MQTT.js automatically convert this protocol from mqtt to ws. Even I used ws://localhost:1883/mqtt but still no change

USE PORT 5000

It works. Thanks man

@rafiulgits any instructions for running single instance of MQTTnet broker both listening on TCP and websocket in .NET CORE Console application?

@shaojun follow the Doc, you'll find how to use both TCP and Websocket. Remember if you use browser as a client the your browser use websocket connection. And to connect your MQTT broker by websocket you have to use HTTP port instead of MQTT default port.

@shaojun Just setup a ASP.NET Core application including kestrel and follow the steps from the Wiki regard the ASP.NET integration.

@rafiulgits I'm using the ASP.NET CORE MVC 3.1, i've followed the doc but this line isn't compiled

endpoints.MapMqtt("/mqtt");

and I have turn to reference the section of ASP.NET Core 2.1+, this finally worked for me:

services.AddMqttWebSocketServerAdapter();

Was this page helpful?
0 / 5 - 0 ratings