我正在尝试通过网站imangular连接到mosquitto mqtt测试服务器。但是,当我尝试连接时,出现以下错误:
与'ws://test.moquitto.org:8080 / mqtt'的WebSocket连接失败:WebSocket握手期间出错:意外的响应代码:500
我不知道自己在想什么。我尝试添加一条路径,该路径也不起作用。
代码:
import { Component, OnInit } from '@angular/core';
import { Paho } from 'ng2-mqtt/mqttws31';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit{
title = 'modular-dashboard';
mqttbroker = 'test.moquitto.org'
private client: Paho.MQTT.Client;
ngOnInit() {
this.client = new Paho.MQTT.Client(this.mqttbroker, 8080, "dbView");
console.log(this.client);
this.client.onMessageArrived = this.onMessageArrived.bind(this);
this.client.onConnectionLost = this.onConnectionLost.bind(this);
this.client.connect({onSuccess: this.onConnect.bind(this)});
}
onConnect() {
console.log('onConnect');
}
onConnectionLost(responseObject) {
if(responseObject.errorCode !== 0 ) {
console.log('onConnectionLost: ' + responseObject );
}
}
onMessageArrived(message) {
console.log('onMessageArrived: ' + message);
}
}