websocket建立连接有些时候能成功,有些时候不能成功。
连接成功并订阅主题后,有些时候能成功收到后台推送的消息,但是大多数时候不能收到,后台消息一直在推送。
let socketUrl="xxxxxx";
var sockJS = new SockJS(socketUrl);
this.stompClient = Stomp.over(sockJS);
window.GpsWebSocket = this.stompClient;
window.GpsWebSocket.onclose=this.WebSocketClose;
window.GpsWebSocket.onerror=this.WebSocketError;
this.stompClient.connect({}, () => {
console.log("WebSocket已连接!");
this.stompClient.subscribe("/users/" + xx + "/xxx", (msg) => {},{})
}, function () {
console.log("WebSocket连接失败!")
});