https://xcstream.github.io/achat/ 打开2个窗口就可以发消息了 代码非常简单易懂
然后呢 源码呢。。
var client = new Paho.MQTT.Client("home.appxc.com", Number(10100), ""+Math.random()) client.onMessageArrived = function(message) { window.vm.messages.push(JSON.parse(message.payloadString).content)} client.connect({useSSL:true, onSuccess:function(){ client.subscribe("public")}}) window.vm=new Vue({ el:'body>div', data:{messages:[], tosend:''}, methods:{ send:function(){ if(this.tosend == "") return var payload = ({content:this.tosend}) var message = new Paho.MQTT.Message(JSON.stringify(payload)) message.destinationName = "public" client.send(message) this.tosend = "" } } }) ````
CNode 社区为国内最专业的 Node.js 开源技术社区,致力于 Node.js 的技术研究。
然后呢 源码呢。。