我不熟悉使用javascript编写的mqtt消息传递客户端。有人能说这段代码是在客户端还是服务器端编写的吗?
client = new Messaging.Client(location.hostname, Number(location.port), "clientId");
client.onConnectionLost = onConnectionLost;
client.onMessageArrived = onMessageArrived;
client.connect({onSuccess:onConnect});
function onConnect() {
// Once a connection has been made, make a subscription and send a message.
console.log("onConnect");
client.subscribe("/World");
message = new Messaging.Message("Hello");
message.destinationName = "/World";
client.send(message);
};
function onConnectionLost(responseObject) {
if (responseObject.errorCode !== 0)
console.log("onConnectionLost:"+responseObject.errorMessage);
};
function onMessageArrived(message) {
console.log("onMessageArrived:"+message.payloadString);
client.disconnect();
};任何人都可以用nodejs、javascript和socket编写服务器代码吗?请把它给我。提前谢谢。
发布于 2013-10-21 19:17:29
处理函数表明它就是客户端。
PS:如果你不介意的话,你能告诉我们这是哪个库吗?谢谢。
发布于 2013-10-21 19:31:24
这使用的是Eclipse Paho javascript客户端http://eclipse.org/paho,它在浏览器中使用。
https://stackoverflow.com/questions/19492138
复制相似问题