sendSocketMessage(){// Listen for openthis.socket.addEventListener("open",(event)=>{this.socket.send(JSON.stringify({info:"message"}));});}
3.接收消息
getSocketMessage(){// Listen for messagethis.socket.addEventListener("message",(event)=>{const data =JSON.parse(event.data);
console.log("Message from server ", data);});}