我无法连接到TCP地址,并且该代码仅连接到websocket。如何将我的代码转换为连接tcp地址?
var app = angular.module('myApp', []);
app.controller('testMQTT', function ($scope) {
var client = new Paho.MQTT.Client("10.218.68.81", Number(1883), "/Sensors/PIM-1/SensorData", "pim1");
client.onConnectionLost = function (responseObject) {
console.log("Connection Lost: " + responseObject.errorMessage);
}
client.onMessageArrived = function (message) {
console.log("Message Arrived: " + message.payloadString);
$scope.$apply();
var jsonObject = JSON.parse(message.payloadString);
console.log(jsonObject);
}
function onConnect() {
$scope.Message = "Connected !";
console.log("connected");
var subscribeOptions = {
qos: 2, // QoS
invocationContext: {
foo: true
}, // Passed to success / failure callback
onSuccess: onSuccessCallback,
onFailure: onFailureCallback,
timeout: 10
};
client.subscribe("/Sensors/PIM-1/SensorData", subscribeOptions);
$scope.$apply();
}
function onSuccessCallback() {}
function onFailureCallback() {}
$scope.Messages = "Connecting !";
// Connect the client, providing an onConnect callback
client.connect({
onSuccess: onConnect
});
})